9951 explained code solutions for 126 technologies


python-pillowHow to set text font


from PIL import Image, ImageDraw, ImageFont

im = Image.open('/var/www/examples/heroine.png')
dr = ImageDraw.Draw(im)
ft = ImageFont.truetype('/var/www/examples/Pacifico.ttf', 160)
dr.text((50, 50), "I am hero", font=ft, fill=(200, 200, 0))

im.show()ctrl + c
PIL

import Pillow package modules

ImageFont.truetype

create font object, with font and size we're going to use for text

/var/www/examples/Pacifico.ttf

path to font to use

160

font size to use

.text(

draws text with given params


How to set text font, python pillow

Usage example

from PIL import Image, ImageDraw, ImageFont

im = Image.open('/var/www/examples/heroine.png')
dr = ImageDraw.Draw(im)
ft = ImageFont.truetype('/var/www/examples/Pacifico.ttf', 160)
dr.text((50, 50), "I am hero", font=ft, fill=(200, 200, 0))

im.show()