[Image-SIG] Spotting PIL text rendering differences for TrueType fonts
gherman at darwin.in-berlin.de
Mon Aug 6 17:27:43 CEST 2012
> On Fri, Aug 3, 2012 at 10:11 AM, Dinu Gherman
> <gherman at darwin.in-berlin.de> wrote:
>> I'm trying to generate bitmap files dynamically using Python, PIL and
>> TrueType fonts. When deploying my code on a WebFaction.com box with
>> a preinstalled PIL I observe nasty differences (most visible in the
>> string widths) in the text being rendered compared to my development
>> box, a MacBook with OS X 10.6 with my own Python/PIL installation
>> (both with Python 2.7.3 and PIL 1.1.7).
>> I've contacted the WebFaction support team, speculating about differ-
>> ences in the JPEG, PNG and/or Freetype libraries used. It's not solved,
>> but now I think Freetype might be the best guess since the output makes
>> no difference between PNG and JPEG. WebFaction told me to install a
>> custom PIL following their recipes here, but that didn't help (in fact
>> the differences compared with my Mac even increased):
>> In order to test this I've written a simple script and put it on Gist
>> here (with two small PNG files attached for an Arial TTF), so people
>> can tweak it if they like:
>> While I haven't given up hope on the WebFaction support I have two
>> questions for this list:
>> 1. I wonder if I can expect the exact same rendering on different
>> platforms with PIL and TrueType at all?
>> 2. Is there some way to tell quickly (ideally at run time) which li-
>> braries (and versions) went into building PIL and, maybe, where
>> they reside in the system?
>> Any help is highly appreciated.
> I don't have much experience with this topic, but you could try
> looking at the selftest.py script that comes with PIL (you probably
> ran it during your install) as I recall it prints some useful
> information out, so it must be able to determine information about the
Well, after some additional tests with many TTFs I concluded that PIL
itself (or Freetype for its sake) must be somehow broken and not quite
able to handle various TTFs consistently, since I get pretty different
results when placing strings for different fonts - even on the same box!
So I abandoned the idea of using PIL for that purpose and switched to
ReportLab instead which seems to use libart for restarization, apparent-
ly including fonts. This gives me predictable output for all fonts and
two different platforms, Mac OS X and WebFaction's CentOS without all
the previous hassle.
More information about the Image-SIG