Skip to content

Instantly share code, notes, and snippets.

@bradmartin333
Created June 1, 2023 01:29
Show Gist options
  • Save bradmartin333/30d827d946ef03bf05411c9debf08be0 to your computer and use it in GitHub Desktop.
Save bradmartin333/30d827d946ef03bf05411c9debf08be0 to your computer and use it in GitHub Desktop.
Mark images with proportional text
from PIL import Image, ImageDraw, ImageFont
import os
filelist = os.listdir(".")
filelist.sort()
jpglist = []
for filename in filelist:
if filename[0] == "g":
jpglist.append(filename)
for filename in jpglist:
im = Image.open(filename)
width, height = im.size
size = int(0.05 * min(width, height))
draw = ImageDraw.Draw(im)
draw.rectangle((0, height - size, size * 6, height), fill="white")
font = ImageFont.truetype("arial.ttf", size)
draw.text((size * 3, height - size / 2), "0.5cm grid", fill="black", anchor="mm", font=font)
im.save("out" + filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment