Search code examples
wand

Why is wand ignoring my unicode characters in text output?


When I use characters such as ≛, ★, etc., wand ignores them in text output. For example:

#!/usr/bin/python3

import os
import wand
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color

with Drawing() as draw:
    draw.fill_color = Color('black')
    draw.font_size = 20
    draw.text (20, 100, 'A')
    draw.text (60, 100, '≛')
    draw.text (100, 100, '▴')
    draw.text (140, 100, 'Z')
    with Image(width=200, height=200, background=Color('yellow')) as img:
        draw(img)
        img.save(filename='example.png')

This yields:

example.png

I'm using macOS 13.2.1's python 3.9.2, and imagemagick via homebrew.


Solution

  • Be sure to define a typeface that includes unicode characters.

    from wand.image import Image
    from wand.drawing import Drawing
    
    with Drawing() as draw:
        draw.fill_color = 'black'
        draw.font_size = 20
        draw.font_family = 'DejaVu Sans'  # <---- Or with draw.font
        draw.text(20, 100, 'A')
        draw.text(60, 100, '≛')
        draw.text(100, 100, '▴')
        draw.text(140, 100, 'Z')
        with Image(width=200, height=200, background='yellow') as img:
            draw(img)
            img.save(filename='example.png')
    

    unicode characters