Text to image with same results on any platform

Gelonida N gelonida at gmail.com
Wed Aug 3 11:40:48 CEST 2011


Hi,


>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