Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Overlay numbers from 0000 to 9999 on a picture
- from PIL import Image, ImageFont, ImageDraw
- BACKGROUND = '/path/to/background.png'
- OUTPUT = '/path/to/mypicture_{0:04d}.png'
- START = 0
- STOP = 9999
- # Create a font object from a True-Type font file and specify the font size.
- fontobj = ImageFont.truetype('/path/to/font/arial.ttf', 24)
- for i in range(START, STOP + 1):
- img = Image.open(BACKGROUND)
- draw = ImageDraw.Draw(img)
- # Write a text over the background image.
- # Parameters: location(x, y), text, textcolor(R, G, B), fontobject
- draw.text((0, 0), '{0:04d}'.format(i), (255, 0, 0), font=fontobj)
- img.save(OUTPUT.format(i))
- print 'Script done!'
Add Comment
Please, Sign In to add comment