[Image-SIG] Truetype representation in Windows and Linux

daniel at roseman.org.uk daniel at roseman.org.uk
Sat Jul 29 20:30:20 CEST 2006


Hi,

I'm using PIL to dynamically create graphical text headers for my website, using a truetype font. Testing this at home on my Windows box works fine. When I upload it to the Linux server, the fonts appear subtly different - the size of the overall image isn't quite right, and the text appears either squashed or spaced wrongly.

Here's the relevant code:

    imf = ImageFont.truetype(fontfile, int(fontsize))
    size = imf.getsize(header)
    im = Image.new("RGB", size, "white")
    draw = ImageDraw.Draw(im)
    draw.text((0, 0), header, font=imf, fill=colour)

With fontfile and fontsize set to the relevant values, and using sample text "Randomtext", this produces an image of size 227x44 on Windows and 229x44 on Linux - doesn't sound like much, but the difference is clearly noticeable (and the designer will kill me). Both machines are running Python 2.4.2 and PIL 1.1.5.

Any ideas, anyone?

--
DR.



More information about the Image-SIG mailing list