Created
June 1, 2023 01:29
-
-
Save bradmartin333/30d827d946ef03bf05411c9debf08be0 to your computer and use it in GitHub Desktop.
Mark images with proportional text
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, 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