Never been to DZone Snippets before?

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

About this user

manatlan http://manatlan.online.fr

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

convert a PIL image to a GTK pixbuf

free adaptation of http://slugathon.python-hosting.com/changeset/205

   1  
   2  import gtk
   3  import Image
   4  
   5  def image2pixbuf(im):  
   6      file1 = StringIO.StringIO()  
   7      im.save(file1, "ppm")  
   8      contents = file1.getvalue()  
   9      file1.close()  
  10      loader = gtk.gdk.PixbufLoader("pnm")  
  11      loader.write(contents, len(contents))  
  12      pixbuf = loader.get_pixbuf()  
  13      loader.close()  
  14      return pixbuf  

convert a GTK pixbuf to a PIL image

   1  
   2  import gtk
   3  import Image
   4  
   5  def pixbuf2Image(pb):
   6     width,height = pb.get_width(),pb.get_height()
   7     return Image.fromstring("RGB",(width,height),pb.get_pixels() )
   8  
   9  pb = gtk.gdk.pixbuf_new_from_file( "p20050424_160333.jpg" )
  10  im = pixbuf2Image(pb)
  11  im.save("welldone.jpg", "JPEG",quality=80)
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS