There is no must in art because art is free.
The following tutorial exaplains how to generate computer art
based on a series of predefined digital images
.
Our script
will combinate all the digital images
generating an specific image collection
We will use the following digital assets
:
4 x backgrounds images
12 x bodies images
12 x faces images
Our script will generate 576 new images
as a result of combinate 4 x 12 x 12
(backgrounds, bodies, and faces).
The script was successfully tested
with:
Python 3.8.5
Pip 21.2.4
Pillow 8.3.2
There is an images
folder with 3 sub-folders
/images/backgrounds
/images/bodies
/images/faces
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
# importing the Pillow module
from PIL import Image, ImageDraw, ImageFilter
# my primary source :D
kBackgrounds = 4
kBodies = 12
kFaces = 12
for index_background in range(1, kBackgrounds + 1):
for index_body in range(1, kBodies + 1):
for index_face in range(1, kFaces + 1):
im1 = Image.open(/path/to/index_background.png)
im2 = Image.open(/path/to/index_body.png)
im3 = Image.open(/path/to/index_face.png)
The magic happens because all the bodies and all the faces have the same canvas/size
!
# paste body into background
im1.paste(im2, (540, 1970), mask=im2)
# paste face into background
im1.paste(im3, (456, 370), mask=im3)
# save!
im1.save(/path/to/new-image.png)
# update status!
print(/path/to/new-image.png, "was successfully created.")