I want to render a string like this ‘3/4’ into a maths fraction.
I can do it by rendering an HTML page and using Mathjax, but that seems a little excessive. Any thoughts much appreciated.
I want to render a string like this ‘3/4’ into a maths fraction.
I can do it by rendering an HTML page and using Mathjax, but that seems a little excessive. Any thoughts much appreciated.
#!/usr/bin/env python3
from PIL import Image, ImageDraw, ImageFont
text1 = u"Unicode maybe? \u00be \u2153 \u2157"
text2 = u"Maths? \u222c \u221e \u220f \u221a"
im = Image.new ( "RGB", (400,100), 0 )
draw = ImageDraw.Draw ( im )
unifont = ImageFont.truetype("/System/Library/Fonts//Menlo.ttc", 32)
draw.text((10,10), text1, font=unifont, fill=(255,255,255))
draw.text((10,55), text2, font=unifont, fill=(255,255,255))
# Save result
im.save("text.png")
Just be sure to use a Unicode font - such as DejaVu.ttf
I used /System/Library/Fonts//Menlo.ttc
because I am on a Mac.
I looked up the codes here.