Skip to content

Instantly share code, notes, and snippets.

@ryansb
Created March 10, 2013 16:34
Show Gist options
  • Save ryansb/5129290 to your computer and use it in GitHub Desktop.
Save ryansb/5129290 to your computer and use it in GitHub Desktop.
Just put an image at ./dec.jpg (or any other image you like) and input your names and you're all set to print as many door decs as you need. Work saved.
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
font = ImageFont.truetype("/usr/share/fonts/dejavu/DejaVuSans.ttf", 75)
namelist = [
# names go here
]
splitnames = []
for i in range(0, len(namelist), 4):
sublist = []
for j in range(i, i + 4):
try:
sublist.append(namelist[j])
except IndexError:
sublist.append("")
splitnames.append(sublist)
img_num = 1
for n1, n2, n3, n4 in splitnames:
img = Image.open('dec.jpg')
draw = ImageDraw.Draw(img)
draw.text((100, 150), n1, (0, 0, 0), font=font)
draw.text((730, 150), n2, (0, 0, 0), font=font)
draw.text((100, 550), n3, (0, 0, 0), font=font)
draw.text((730, 550), n4, (0, 0, 0), font=font)
draw = ImageDraw.Draw(img)
img.save("doordec_%s.png" % img_num)
img_num += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment