Created
February 24, 2022 11:58
-
-
Save pemagrg1/d8c0b5cd9c1b5b85b462c96bbe915ccd to your computer and use it in GitHub Desktop.
Adding text on multiple images. (Can be used specially for invitation cards)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
from PIL import ImageDraw | |
from PIL import ImageFont | |
names = ["Pema", "Gurung", "Pema Gurung"] | |
for name in names: | |
myFont = ImageFont.truetype( | |
'/Downloads/precious/Precious.ttf', 65) | |
img = Image.open( | |
'/Downloads/2a3ccc38-bc64-41a1-8092-0a2e9e742484.JPG') | |
MAX_W, MAX_H = img.size | |
current_h, pad = 430, 200 | |
I1 = ImageDraw.Draw(img) | |
w, h = I1.textsize(name, font=myFont) | |
I1.text(((MAX_W - w) / 2, current_h), name, font=myFont, fill=(0, 0, 0)) | |
img.show() | |
# img.save(name+".png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment