By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,765 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,765 IT Pros & Developers. It's quick & easy.

Python Imaging Library and PyGTK - color image path?

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Fri, 22 Apr 2005 22:43:13 -0400, Jeremy Bowers wrote:
(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....
Jul 19 '05 #2

P: n/a
Jeremy Bowers wrote:
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/pygt...il/009988.html

which provides a StringIO-based solution, and

http://www.daa.com.au/pipermail/pygt...ry/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/py***@da.../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>

Jul 19 '05 #3

P: n/a
On Sat, 23 Apr 2005 10:20:29 +0200, Fredrik Lundh wrote:
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/py***@da.../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.)
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.