├── .gitignore ├── images ├── backgrounds │ ├── 01.png │ ├── 02.png │ ├── 03.png │ └── 04.png ├── bodies │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ └── 12.png └── faces │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ └── 12.png ├── index.py ├── install.txt └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac 2 | .DS_Store 3 | 4 | # Project 5 | outputs/ 6 | 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | *.py[cod] 10 | *$py.class 11 | 12 | # C extensions 13 | *.so 14 | 15 | # Distribution / packaging 16 | .Python 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | .eggs/ 23 | lib/ 24 | lib64/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | wheels/ 29 | pip-wheel-metadata/ 30 | share/python-wheels/ 31 | *.egg-info/ 32 | .installed.cfg 33 | *.egg 34 | MANIFEST 35 | 36 | # PyInstaller 37 | # Usually these files are written by a python script from a template 38 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 39 | *.manifest 40 | *.spec 41 | 42 | # Installer logs 43 | pip-log.txt 44 | pip-delete-this-directory.txt 45 | 46 | # Unit test / coverage reports 47 | htmlcov/ 48 | .tox/ 49 | .nox/ 50 | .coverage 51 | .coverage.* 52 | .cache 53 | nosetests.xml 54 | coverage.xml 55 | *.cover 56 | *.py,cover 57 | .hypothesis/ 58 | .pytest_cache/ 59 | 60 | # Translations 61 | *.mo 62 | *.pot 63 | 64 | # Django stuff: 65 | *.log 66 | local_settings.py 67 | db.sqlite3 68 | db.sqlite3-journal 69 | 70 | # Flask stuff: 71 | instance/ 72 | .webassets-cache 73 | 74 | # Scrapy stuff: 75 | .scrapy 76 | 77 | # Sphinx documentation 78 | docs/_build/ 79 | 80 | # PyBuilder 81 | target/ 82 | 83 | # Jupyter Notebook 84 | .ipynb_checkpoints 85 | 86 | # IPython 87 | profile_default/ 88 | ipython_config.py 89 | 90 | # pyenv 91 | .python-version 92 | 93 | # pipenv 94 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 95 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 96 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 97 | # install all needed dependencies. 98 | #Pipfile.lock 99 | 100 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 101 | __pypackages__/ 102 | 103 | # Celery stuff 104 | celerybeat-schedule 105 | celerybeat.pid 106 | 107 | # SageMath parsed files 108 | *.sage.py 109 | 110 | # Environments 111 | .env 112 | .venv 113 | env/ 114 | venv/ 115 | ENV/ 116 | env.bak/ 117 | venv.bak/ 118 | 119 | # Spyder project settings 120 | .spyderproject 121 | .spyproject 122 | 123 | # Rope project settings 124 | .ropeproject 125 | 126 | # mkdocs documentation 127 | /site 128 | 129 | # mypy 130 | .mypy_cache/ 131 | .dmypy.json 132 | dmypy.json 133 | 134 | # Pyre type checker 135 | .pyre/ 136 | -------------------------------------------------------------------------------- /images/backgrounds/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/backgrounds/01.png -------------------------------------------------------------------------------- /images/backgrounds/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/backgrounds/02.png -------------------------------------------------------------------------------- /images/backgrounds/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/backgrounds/03.png -------------------------------------------------------------------------------- /images/backgrounds/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/backgrounds/04.png -------------------------------------------------------------------------------- /images/bodies/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/01.png -------------------------------------------------------------------------------- /images/bodies/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/02.png -------------------------------------------------------------------------------- /images/bodies/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/03.png -------------------------------------------------------------------------------- /images/bodies/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/04.png -------------------------------------------------------------------------------- /images/bodies/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/05.png -------------------------------------------------------------------------------- /images/bodies/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/06.png -------------------------------------------------------------------------------- /images/bodies/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/07.png -------------------------------------------------------------------------------- /images/bodies/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/08.png -------------------------------------------------------------------------------- /images/bodies/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/09.png -------------------------------------------------------------------------------- /images/bodies/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/10.png -------------------------------------------------------------------------------- /images/bodies/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/11.png -------------------------------------------------------------------------------- /images/bodies/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/bodies/12.png -------------------------------------------------------------------------------- /images/faces/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/01.png -------------------------------------------------------------------------------- /images/faces/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/02.png -------------------------------------------------------------------------------- /images/faces/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/03.png -------------------------------------------------------------------------------- /images/faces/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/04.png -------------------------------------------------------------------------------- /images/faces/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/05.png -------------------------------------------------------------------------------- /images/faces/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/06.png -------------------------------------------------------------------------------- /images/faces/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/07.png -------------------------------------------------------------------------------- /images/faces/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/08.png -------------------------------------------------------------------------------- /images/faces/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/09.png -------------------------------------------------------------------------------- /images/faces/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/10.png -------------------------------------------------------------------------------- /images/faces/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/11.png -------------------------------------------------------------------------------- /images/faces/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computer-art/example/5f75281382379985da1a463a738d0a48d1808f83/images/faces/12.png -------------------------------------------------------------------------------- /index.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | # ======================================== 4 | # Modules 5 | # ======================================== 6 | 7 | # importing the os module 8 | import os 9 | 10 | # importing the Pillow module 11 | from PIL import Image, ImageDraw, ImageFilter 12 | 13 | # ======================================== 14 | # User defined values 15 | # ======================================== 16 | 17 | # some constants 18 | kBackgrounds = 4 19 | kBodies = 12 20 | kFaces = 12 21 | 22 | # to get the current script directory 23 | kDirectory = os.path.dirname(os.path.realpath(__file__)) 24 | 25 | # create outputs if not exists 26 | if not os.path.exists(kDirectory + '/outputs'): 27 | os.makedirs(kDirectory + '/outputs') 28 | 29 | # ======================================== 30 | # Go go go! 31 | # ======================================== 32 | 33 | # loop through each background 34 | for index_background in range(1, kBackgrounds + 1): 35 | 36 | # loop through each body 37 | for index_body in range(1, kBodies + 1): 38 | 39 | # loop through each face 40 | for index_face in range(1, kFaces + 1): 41 | 42 | # the combination 43 | index_combination = f'{index_background:03}' + "-" + f'{index_body:03}' + "-" + f'{index_face:03}' 44 | 45 | # the files 46 | background = kDirectory + '/images/backgrounds/' + f'{index_background:02}' + '.png' 47 | body = kDirectory + '/images/bodies/' + f'{index_body:02}' + '.png' 48 | face = kDirectory + '/images/faces/' + f'{index_face:02}' + '.png' 49 | output = kDirectory + '/outputs/' + index_combination + '.png' 50 | 51 | # some validations 52 | if not os.path.exists(background): 53 | print("file not exists", background) 54 | exit(-1) 55 | 56 | if not os.path.exists(body): 57 | print("file not exists", body) 58 | exit(-1) 59 | 60 | if not os.path.exists(face): 61 | print("file not exists", face) 62 | exit(-1) 63 | 64 | # load the images 65 | im1 = Image.open(background) 66 | im2 = Image.open(body) 67 | im3 = Image.open(face) 68 | 69 | # paste body into background 70 | im1.paste(im2, (540, 1970), mask=im2) 71 | im1.paste(im3, (456, 370), mask=im3) 72 | 73 | # save! 74 | im1.save(output) 75 | 76 | # update status! 77 | print(output, "was successfully created.") 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /install.txt: -------------------------------------------------------------------------------- 1 | pip install Pillow -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Computer Art 2 | 3 | > There is no must in art because art is free. 4 | 5 | 6 | ## Introduction 7 | 8 | The following tutorial exaplains how to generate `computer art` based on a series of predefined `digital images`. 9 | Our `script` will combinate all the `digital images` generating an specific `image collection` 10 | 11 | ## Example Case 12 | 13 | We will use the following `digital assets`: 14 | 15 | - `4 x backgrounds images` 16 | - `12 x bodies images` 17 | - `12 x faces images` 18 | 19 | ## Expected Results 20 | 21 | Our script will generate `576 new images` as a result of combinate `4 x 12 x 12` (backgrounds, bodies, and faces). 22 | 23 | ![Example](https://i.ibb.co/CpLnRrB/all.jpg) 24 | 25 | ## Environment 26 | 27 | The script was `successfully tested` with: 28 | 29 | - `Python 3.8.5` 30 | - `Pip 21.2.4` 31 | - `Pillow 8.3.2` 32 | 33 | ## Digital Assets 34 | 35 | There is an `images` folder with `3 sub-folders` 36 | 37 | - `/images/backgrounds` 38 | - `/images/bodies` 39 | - `/images/faces` 40 | 41 | Inside `each sub-folder` there is a few `transparent png files` named with `2-left pad zero` strategy, for example: `01.png`, `02.png`, `...`, `11.png` 42 | 43 | ## Script Strategy 44 | 45 | ### 1. Import Pillow Module 46 | 47 | ```python 48 | # importing the Pillow module 49 | from PIL import Image, ImageDraw, ImageFilter 50 | ``` 51 | 52 | ### 2. Define how many digital assets will combine 53 | 54 | ```python 55 | # my primary source :D 56 | kBackgrounds = 4 57 | kBodies = 12 58 | kFaces = 12 59 | ``` 60 | 61 | ### 3. Loop in order 62 | 63 | ```python 64 | for index_background in range(1, kBackgrounds + 1): 65 | for index_body in range(1, kBodies + 1): 66 | for index_face in range(1, kFaces + 1): 67 | ``` 68 | 69 | ### 4. Load the 3 images that will generate the current new image 70 | 71 | ```python 72 | im1 = Image.open(/path/to/index_background.png) 73 | im2 = Image.open(/path/to/index_body.png) 74 | im3 = Image.open(/path/to/index_face.png) 75 | ``` 76 | 77 | ### 5. Paste `img2` and `img3` into `img1` in the right position 78 | 79 | ![Example](https://i.ibb.co/nzDw233/example.jpg) 80 | 81 | The magic happens because all the bodies and all the faces have the same `canvas/size`! 82 | 83 | ```python 84 | # paste body into background 85 | im1.paste(im2, (540, 1970), mask=im2) 86 | # paste face into background 87 | im1.paste(im3, (456, 370), mask=im3) 88 | ``` 89 | 90 | ### 6. Save & continue the loop with the next combination! 91 | 92 | ```python 93 | # save! 94 | im1.save(/path/to/new-image.png) 95 | 96 | # update status! 97 | print(/path/to/new-image.png, "was successfully created.") 98 | ``` 99 | 100 | ## Bye! 101 | 102 | ![Example](https://i.ibb.co/x7H5dMb/003-008-011.png) 103 | --------------------------------------------------------------------------------