DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Convert A PIL Image To A GTK Pixbuf
free adaptation of http://slugathon.python-hosting.com/changeset/205
import gtk
import Image
def image2pixbuf(im):
file1 = StringIO.StringIO()
im.save(file1, "ppm")
contents = file1.getvalue()
file1.close()
loader = gtk.gdk.PixbufLoader("pnm")
loader.write(contents, len(contents))
pixbuf = loader.get_pixbuf()
loader.close()
return pixbuf






Comments
Snippets Manager replied on Sat, 2010/09/04 - 7:45am
import gtk import Image import StringIO def image2pixbuf(im): file1 = StringIO.StringIO() im.save(file1, "ppm") contents = file1.getvalue() file1.close() loader = gtk.gdk.PixbufLoader("pnm") loader.write(contents, len(contents)) pixbuf = loader.get_pixbuf() loader.close() return pixbuf im = Image.open(imageFile) pixbuf = image2pixbuf(im)