Skip to content

Instantly share code, notes, and snippets.

@sshopov
Created September 3, 2014 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshopov/ee7a5cdeee925024d9e3 to your computer and use it in GitHub Desktop.
Save sshopov/ee7a5cdeee925024d9e3 to your computer and use it in GitHub Desktop.
I had an icon representing a little blue dot and needed to create 100 copies each with a number in them. Python saves the day yet again. Tags: Python, PIL, Pillow
#requires http://www.pythonware.com/products/pil/ or https://github.com/python-pillow/Pillow
import Image, ImageFont, ImageDraw
def add_number(number):
'''Add the number to the center of an icon and save it to a new image
Useful for generating multiple icons'''
image = Image.open(r'C:\python\temp\bd.png')
font=ImageFont.truetype("arial.ttf", 55) #, encoding='utf-8')
draw=ImageDraw.Draw(image)
x=(image.size[0]-draw.textsize(number,font)[0])/2
y=(image.size[1]-draw.textsize(number,font)[1])/2
draw.text((x,y),number,font=font,fill='#FFFFFF')
#image.show()
image.save(r'C:\python\temp\bd%s.png'%number)
for i in range(1,101):
add_number(str(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment