[pygtk] gtk.Image write text inside Image

David Ripton dripton at ripton.net
Sat Nov 8 03:06:31 WST 2008


On 2008.11.07 15:21:29 +0000, Luis Gonzalez wrote:
> I have a gtk.Image load from file.
> 
> I want to write text inside this Image and then write to a file (jpg or png).
> 
> I try to do use gtk.gdk.Pixbuf but to write text , draw lines , draw rectangle I need a drawable object like gtk.gdk.Pixmap.
> 
> How can i do this?

The last time I needed to do this (in 2005), I had problems with PyGTK's
image manipulation abilities / API / docs, and ended up using Python
Imaging Library from inside my PyGTK program.

I have some code PyGTK + PIL code that you can look at here:

http://slugathon.python-hosting.com/file/trunk/slugathon/Chit.py

It loads a base image from a PNG file into PIL, then uses PIL to draw
lines and text on it, then takes the final image and saves it to a file
format that PyGTK understands (via a StringIO, though you could use a
real file instead), so that PyGTK can load it into a pixbuf.

PyGTK gets better every release, and its docs have improved too, so
maybe it's no longer necessary to resort to PIL.  But it's an option to
consider.

-- 
David Ripton    dripton at ripton.net


More information about the pygtk mailing list