0

I am trying to convert some non-ASCII strings to an image but am running into issues because of font limitations.

My code

from PIL import Image,ImageDraw, ImageFont

s1 = 'Hⅰ Нοѡ aᏒÈ yoμ?'

image = np.zeros((100, 950, 3), dtype=np.uint8)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
pil_image = Image.fromarray(image)

font = ImageFont.truetype(r'../input/arialttf-font/arial.ttf', 35)
draw = ImageDraw.Draw(pil_image)
draw.text((30, 30), s1, font=font)

pil_image

The Output I get from this

enter image description here

The Output I am trying to get

enter image description here

yohoo
  • 165
  • 1
  • 2
  • 13
  • 2
    If you copy and paste that text into Word, in a document that has Arial set as its font, you'll find that Word will try and match other fonts to some of the characters, in an attempt to preserve the text - even if you select the text and explicitly set the font. Not all the characters in your text are actually in the Arial font. Find a font that has all of them. – Grismar Oct 19 '22 at 23:47
  • 3
    Relevant [thread](https://stackoverflow.com/questions/34732718/why-isnt-there-a-font-that-contains-all-unicode-glyphs). Try a font that covers more than what Arial provides, such as [unifont](http://www.unifoundry.com/unifont/index.html). – metatoaster Oct 19 '22 at 23:55

0 Answers0