Created
April 17, 2016 23:49
-
-
Save azhtom/fc3ca79f219b1339c27724bcf956da24 to your computer and use it in GitHub Desktop.
horizontally center align text with PIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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