Skip to content

Instantly share code, notes, and snippets.

@azhtom
Created April 17, 2016 23:49
Show Gist options
  • Save azhtom/fc3ca79f219b1339c27724bcf956da24 to your computer and use it in GitHub Desktop.
Save azhtom/fc3ca79f219b1339c27724bcf956da24 to your computer and use it in GitHub Desktop.
horizontally center align text with PIL
font_size = 60
text = 'your text'
rgb_color = (255,255,255)
img = Image.open('your-image.jpg')
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('your-font.ttf', font_size)
w, h = draw.textsize(text, font)
left = (img.width - w) / 2
top = 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment