We have tried this before, but now we add the ImageFont class to make this thing better.
from PIL import Image,ImageDraw,ImageFont # sample text and font unicode_text = u"Hello World!" font = ImageFont.truetype("consola.ttf", 28, encoding="unic") # get the line size text_width, text_height = font.getsize(unicode_text) # create a blank canvas with extra space between lines canvas = Image.new('RGB', (text_width + 10, text_height + 10), "orange") # draw the text onto the text canvas, and use black as the text color draw = ImageDraw.Draw(canvas) draw.text((5,5), u'Hello World!', 'blue', font) # save the blank canvas to a file #canvas.save("unicode-text.png", "PNG") canvas
Comments
Post a Comment