PIL question. having exactly same font on multiple platforms

Irmen de Jong irmen.NOSPAM at xs4all.nl
Thu Aug 4 21:30:59 CEST 2011


On 4-8-2011 20:54, Gelonida N wrote:

> The reason why I want the images to  look identical is very simple.
> Though the final web server will run on a linux server, I use sometimes
> windows for development or as test server.
> 
> For automated tests I would have liked pixel identical images.
> this allows calculating the md5sum of images to know whether
> a regression in the image layout occured. Well I can live without it.

Then don't run your automated tests on the dev server but deploy your stuff to a
separate test server first, that runs the same software as production. And run the tests
there.


> The second (more import issue) is, that the images should look the same
> whether created on a Windows or Linux host.
> 
> I didn't know that PIL delegated font rendering to the underlying OS,
> but thought it contains its own rendering.

I'm pretty sure it does have that indeed; it links with the freetype library. Are you
sure you're not just seeing differences because of differences in the typeface itself?

A courier.ttf on one system can look very different from a ms-courier-new.ttf on another...

> Here the problem is not if a few pixels are different, but currently I
> even don't know how to choose a font, and make sure it exists on both
> platforms. I also don't know how I can write portable python code,  that
> will find a given font on windows and on linux independent of the exact
> font location.

I once made a module that uses PIL to draw captcha images. It uses one of the free
truetype font files that I just place next to the code. I downloaded the ttf files from
http://www.fontgirl.com/  but there are dozens of free font sites. Just be sure to check
the license terms of the the typeface files.

As far as I know, I did not see any difference in output on windows, linux and mac os x
as long as the code used the same ttf file and PIL versions. (but I'll double check now
and see if I remember this correctly).

Irmen



More information about the Python-list mailing list