Skip to content

Computer art based on joining transparent images

Notifications You must be signed in to change notification settings

computer-art/example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

Computer Art

There is no must in art because art is free.

Introduction

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

Example Case

We will use the following digital assets:

  • 4 x backgrounds images
  • 12 x bodies images
  • 12 x faces images

Expected Results

Our script will generate 576 new images as a result of combinate 4 x 12 x 12 (backgrounds, bodies, and faces).

Example

Environment

The script was successfully tested with:

  • Python 3.8.5
  • Pip 21.2.4
  • Pillow 8.3.2

Digital Assets

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

Script Strategy

1. Import Pillow Module

# importing the Pillow modulefromPILimportImage, ImageDraw, ImageFilter

2. Define how many digital assets will combine

# my primary source :DkBackgrounds=4kBodies=12kFaces=12

3. Loop in order

forindex_backgroundinrange(1, kBackgrounds+1): forindex_bodyinrange(1, kBodies+1): forindex_faceinrange(1, kFaces+1):

4. Load the 3 images that will generate the current new image

im1=Image.open(/path/to/index_background.png) im2=Image.open(/path/to/index_body.png) im3=Image.open(/path/to/index_face.png)

5. Paste img2 and img3 into img1 in the right position

Example

The magic happens because all the bodies and all the faces have the same canvas/size!

# paste body into backgroundim1.paste(im2, (540, 1970), mask=im2) # paste face into backgroundim1.paste(im3, (456, 370), mask=im3)

6. Save & continue the loop with the next combination!

# save!im1.save(/path/to/new-image.png) # update status!print(/path/to/new-image.png, "was successfully created.")

Bye!

Example

Releases

No releases published

Packages

No packages published

Languages