Monday, September 15, 2014

Render font file ttf with python

-- the following script use font NIDATaprom.ttf in directory fonts then will generate an image font-image.jpg with rendered font


#!/usr/bin/python

from PIL import Image, ImageDraw, ImageFont

fontPath = "fonts/NiDATaprom.ttf"

font1  =  ImageFont.truetype ( fontPath,16 )
im  =  Image.new ( "RGB", (1000,100), "white" )

draw  =  ImageDraw.Draw ( im )


text2 = "Font to display in the images "
draw.text ( (0,0), text2, font=font1,fill="black" )

im.save ( "font-image.jpg" )

-------------------------
font-image.jpg


No comments:

Post a Comment