PyFT and PIL

Robert Kern kern at myrddin.caltech.edu
Mon Apr 23 06:49:27 EDT 2001


In article <mailman.987996754.9967.python-list at python.org>,
	"Chris Gonnerman" <chris.gonnerman at usa.net> writes:
> Would someone be able to show a working example of PyFT drawing with
> "correct" alpha transparency on a PIL pixmap image?  This is the main
> reason I took over the GD module... I have lots of TrueType fonts and
> would like to use them to draw on pictures (i.e. website buttons etc.)
> 
> I could probably figure it out, but I assume someone already has.  A
> Google search doesn't turn up anything useful (or I'm not doing it
> right).

Among other reasons, I updated PyFT to handle that gracefully. Because of 
unavailability of web space for some time, I had only semi-released it. It
is now at 
http://starship.python.net/crew/kernr/source/PyFT-0.65.tar.gz

It has a nice class-based wrapper around the nasty function calls. One does
essentially the following:

>>> f = Font('times', size=12, bold=0, italic=1)
>>> rend = BaseRenderer(resolution=(96,96), aa=1)
>>> rend.drawString(PIL_image, 'FooBar', x_pos, y_pos, f)

and 'FooBar' will be rendered in 12-point, italic Times New Roman onto the 
PIL Image instance PIL_Image with the appropriate alpha mask.

Just set up the font locations correctly at the beginning of the PyFT.py file.

I have given up maintenance of PyFT since I've moved onto other things.
Steve Alexander has offered to take it over. Of course, someone (not me)
should write a new PyFT from scratch to wrap FreeType2.

-- 
Robert Kern
kern at caltech.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the Python-list mailing list