I'm passing a string to PIL
's multiline_text()
which, for some reason, doesn't support utf-8 but only Latin characters.
from PIL import Image, ImageDraw
input_string = "‘Hi’"
img_width = 500
img_height = 500
img = Image.new('RGB', (img_width, img_height), (255, 255, 255))
img_D = ImageDraw.Draw(img)
img_D.multiline_text((0, 0), input_string) # <- bug here
img.save("test_img.jpeg", 'jpeg', optimize=True, quality = 200)
I get this error message: UnicodeEncodeError: 'latin-1' codec can't encode character '\u2018' in position 0: ordinal not in range(256)
So I need to get rid of all non-Latin characters. How can I do that?
Note: I've seen this answer, namely input_string = regex.sub(ur'[^\p{Latin}]', u'', t1)
but I'm pretty sure it's for Python2, I get the following error: SyntaxError: invalid syntax
. If I remove either the u
or the r
or both, I get error: bad escape \p
.