PIL question. having exactly same font on multiple platforms

Gelonida N gelonida at gmail.com
Thu Aug 4 06:04:27 EDT 2011


I posted already a  question, but perhaps the subject line wasn't clear.


Subject line was "Text to image with same results on any platform"


>From within a django application
I'd like create a small image file (e.g. .png)
which just contains some text.

I wondered what library would be appropriate and would yield the same
result independent of the OS (assuming the versions of the python
libraries are the same)
Images should be pixel identical independent on the platform on which
the image is created.

I made some attempts with PIL (Image / ImageFont / ImageDraw),
but have difficulties getting the same font under Linux and windows.


# ------------------------code starts here
import Image
import ImageFont
import ImageDraw

# Here I don't know how to get the same font file
# for all platforms
# Perhaps there is a tiny trick that I overlooked.
font_file = get_font_file_name()
# Is truetype a good choice for portable fonts?
font = ImageFont.truetype(font_file, 20)

img = Image.new("RGB", (800, 600), "#FFFFFF")
draw = ImageDraw.Draw(image)

draw.text( (100, 100), font=font, fill="#00FF00")
# ---------------------------- end of code


I could also install any other library (matplotlib??)
if it were capable of creating consistent images
independent on the platform.

Thanks in advance for any suggestions.













More information about the Python-list mailing list