Search code examples
python-3.xpython-imaging-librarypython-unicode

Draw tickmark or checkmark with PIL


I tried Arial, Wingdings and other fonts... but can't get the tickmark printed on my image. Please let me know what am I doing wrong?

Code:

from PIL import Image, ImageDraw, ImageFont, ImageFilter

font_size=36
width=500
height=100
back_ground_color=(255,255,255)
font_size=36
font_color=(0,0,0)
unicode_text = u"\u2714"   # Heavy tickmark
unicode_text = u"\u2713"   # Regular tickmark

im  =  Image.open("img_path").convert('RGB') 
draw  =  ImageDraw.Draw ( im )
font1 = ImageFont.truetype("Wingding.ttf", 40, encoding="UTF-8")
font2 = ImageFont.truetype('arial.ttf', 40)
font3 = ImageFont.truetype("Wingding.ttf", 40)

draw.text ( (10,10), unicode_text, font=font1, fill=font_color )
draw.text ( (20,40), unicode_text, font=font2, fill=font_color )
draw.text ( (30,80), unicode_text, font=font3, fill=font_color )

im.save("text.jpg")

Solution

  • You need to use a font with that character, e.g. DejaVuSans:

    from PIL import Image, ImageDraw, ImageFont
    
    im   =  Image.new('RGB', (200,200), 'white')
    draw =  ImageDraw.Draw (im)
    font = ImageFont.truetype("DejaVuSans.ttf", 40, encoding="UTF-8")
    unicode_text = u"\u2713"   # Regular tickmark
    draw.text ( (10,10), unicode_text, font=font)