Python Imaging Library and PyGTK - color image path?

J

Jeremy Bowers

I have an image in the Python Image Library. I'm trying to get it into
PyGTK in color. Is there any way to do this cross-platform, preferably
without writing to anything to the disk?

PIL apparently can't write XPMs. GTK will only take XPMs, that I can see.
Therein lies the rub. I can ship over monochrome bitmaps via XBM, but I'd
rather be able to ship over full color.

(Use case, in case it matters: I am trying to embed a graphic into a text
widget. This is going fine. Because I want the text widget to be able use
different size text, and no one image can look right with everything from
8pt to 40pt text (all reasonable possibilities), I load a large image in
from the disk and scale it down as needed; the images are designed to
scale well and later I can make multiple source images if that is
desirable. But I can't figure out how to get the scaled image into GTK.
This surprises me.)

If there's an easy Google search, it has eluded me.
 
J

Jeremy Bowers

(Use case, in case it matters: I am trying to embed a graphic into a text
widget. This is going fine. Because I want the text widget to be able use
different size text, and no one image can look right with everything from
8pt to 40pt text (all reasonable possibilities), I load a large image in
from the disk and scale it down as needed; the images are designed to
scale well and later I can make multiple source images if that is
desirable. But I can't figure out how to get the scaled image into GTK.
This surprises me.)

As usual, posting for help after poking around for a long while guarantees
you'll figure it out in the next few minutes. You need to create GDK
pixbufs, which can be resized and scaled and stuff.

There is definitely some room for confusion here with GTK Images, GDK
Images, GTK pixbufs, and GDK pixbufs....
 
F

Fredrik Lundh

Jeremy said:
I have an image in the Python Image Library. I'm trying to get it into
PyGTK in color. Is there any way to do this cross-platform, preferably
without writing to anything to the disk?

PIL apparently can't write XPMs. GTK will only take XPMs, that I can see.
Therein lies the rub. I can ship over monochrome bitmaps via XBM, but I'd
rather be able to ship over full color.

the first two google hits for "PyGTK PIL" are

http://www.daa.com.au/pipermail/pygtk/2005-April/009988.html

which provides a StringIO-based solution, and

http://www.daa.com.au/pipermail/pygtk/2003-February/004393.html

which discusses draw_rgb_image and friends, and says that "if you can convert
your PIL image to a pixel data string or buffer object, you could use them to
display the image". here's some code that seems to do exactly that:

http://www.mail-archive.com/[email protected]/msg07167.html

(but maybe this is some kind of stupid "a bitmap isn't a pixmap isn't an image"
thing? if so, I suggest getting a modern windowing system ;-)

</F>
 
J

Jeremy Bowers

which discusses draw_rgb_image and friends, and says that "if you can
convert your PIL image to a pixel data string or buffer object, you could
use them to display the image". here's some code that seems to do exactly
that:

http://www.mail-archive.com/[email protected]/msg07167.html

(but maybe this is some kind of stupid "a bitmap isn't a pixmap isn't an
image" thing? if so, I suggest getting a modern windowing system ;-)

A varient; I was missing the gdk.pixbuf because I assumed that because
there was a gtk.pixbuf that I knew about, that I had all relevant data.
Were that the only pixbuf, that would be an atrocity. (Particularly odd
for GTK, the *Gimp* windowing toolkit.)

(It of course figures that was the google search; I think I tried
everything but that; "python imaging library" "pygtk" isn't anywhere near
as helpful, for instance.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top