Skip to content

Instantly share code, notes, and snippets.

@pemagrg1
Created February 24, 2022 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pemagrg1/d8c0b5cd9c1b5b85b462c96bbe915ccd to your computer and use it in GitHub Desktop.
Save pemagrg1/d8c0b5cd9c1b5b85b462c96bbe915ccd to your computer and use it in GitHub Desktop.
Adding text on multiple images. (Can be used specially for invitation cards)
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