Guest User

Untitled

a guest
Aug 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. Overlay numbers from 0000 to 9999 on a picture
  2. from PIL import Image, ImageFont, ImageDraw
  3.  
  4. BACKGROUND = '/path/to/background.png'
  5. OUTPUT = '/path/to/mypicture_{0:04d}.png'
  6. START = 0
  7. STOP = 9999
  8.  
  9. # Create a font object from a True-Type font file and specify the font size.
  10. fontobj = ImageFont.truetype('/path/to/font/arial.ttf', 24)
  11.  
  12. for i in range(START, STOP + 1):
  13. img = Image.open(BACKGROUND)
  14. draw = ImageDraw.Draw(img)
  15. # Write a text over the background image.
  16. # Parameters: location(x, y), text, textcolor(R, G, B), fontobject
  17. draw.text((0, 0), '{0:04d}'.format(i), (255, 0, 0), font=fontobj)
  18. img.save(OUTPUT.format(i))
  19.  
  20. print 'Script done!'
Add Comment
Please, Sign In to add comment