[Image-SIG] TrueType fonts under PIL

goat at tirfa.com goat at tirfa.com
Thu Feb 15 01:21:33 CET 2007

I think that I figured out why things didn't look like I wanted.

I am writing text on a template gif image and wasn't converting it to  
a RGB image. In order to get the text to show up, I was changing the  
image's palette to include black (rgb(0,0,0)) and then using that new  
palette color to write text on the image. Since the truetype fonts  
seem to be rendered in greyscale rather than monochrome, anything that  
wasn't pure black wouldn't show up on the final image.

When I work with RGB bmp files, everything looks wonderful but looks  
horrible when I re-encode the bmp to gif.

So the moral of the story seems to be: be careful about writing  
truetype text in monochrome.


Quoting Joachim Thöne <rijoth at gmx.de>:

> goat at tirfa.com schrieb:
>> I have been writing a python script that automatically makes button  
>>   images from text files and I have some questions about the   
>> TrueType  font rendering in PIL 1.1.6 under Python 2.5 under Win32   
>> (used the  installer).
>> I have been having some issues with glyphs either not rendering    
>> completely or not rendering at all(the ones that I have noticed are  
>>   '_' and the descender (http://en.wikipedia.org/wiki/Descender)  
>> for   lower case 'g'). After some playing around, I found that this  
>>  seems to be mostly dependent on font size. Depending on which font  
>>  I use, the  size at which everything renders correctly changes but  
>>  they render  correctly at some sizes and don't when I use other   
>> sizes.
>> Does anyone have any suggestions on what I can do to improve   
>> TrueType  font rendering without changing the font size?
>> Thanks for your time,
>> Tim
>> Environment Information:
>> Windows XP SP2
>> Python 2.5 (.msi version from python.org)
>> PIL 1.1.6 (downloaded .msi for python 2.5)
>> Font: I've tried several, but the one that I have been using most   
>> is  IPA Mona Gothic (ipag-mona.ttf) which is a Japanese language   
>> font  available from http://www.geocities.jp/ipa_mona/ and I   
>> believe that it is used in several FOSS projects.
>> _______________________________________________
>> Image-SIG maillist  -  Image-SIG at python.org
>> http://mail.python.org/mailman/listinfo/image-sig
> Hello Tim,
> I've loaded ipag-mona.ttf fontfile into PIL via the aggdraw library (an
> extension for Pil, that does not use PIL to load the font) with an
> identical result to yours. Migtht be that the fontfile is buggy, I've
> never had troubles with displaying .ttf fonts in PIL.
> Joachim

More information about the Image-SIG mailing list