upwart
Apr 03, 2014 - 12:00
I want use PIL to create my own picture, including texts.
I can draw the string, but don't know how to use another font or change the size.
I want use PIL to create my own picture, including texts.
I can draw the string, but don't know how to use another font or change the size.
If this is for use in a scene.Scene then check out https://gist.github.com/cclauss/6532692 which contains a line:
(imageName, imageSize) = scene.render_text(inFontName, font_name=inFontName, font_size=64)
Or you can try a more PIL oriented solution like: http://stackoverflow.com/questions/16373425/add-text-on-image-using-pil
Also check out the Meme Generator script: http://ipad.appstorm.net/how-to/utilities/pythonista-101-python-wrangling
Here's a simple example of using ImageDraw with a custom font:
import Image, ImageDraw, ImageFont
img = Image.new('RGBA', (210, 90), 'white')
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('Chalkduster', 72)
draw.text((0, 0), 'Hello', fill='blue', font=font)
img.show()
You can access a list of available fonts from the [+] button (iPad), or by using the "Insert…" menu item (iPhone).