Python Imaging Library and PyGTK - color image path?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy Bowers

    #1

    Python Imaging Library and PyGTK - color image path?

    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.
  • Jeremy Bowers

    #2
    Re: Python Imaging Library and PyGTK - color image path?

    On Fri, 22 Apr 2005 22:43:13 -0400, Jeremy Bowers wrote:[color=blue]
    > (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.)[/color]

    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....

    Comment

    • Fredrik Lundh

      #3
      Re: Python Imaging Library and PyGTK - color image path?

      Jeremy Bowers wrote:
      [color=blue]
      >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.[/color]

      the first two google hits for "PyGTK PIL" are



      which provides a StringIO-based solution, and



      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:



      (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>

      Comment

      • Jeremy Bowers

        #4
        Re: Python Imaging Library and PyGTK - color image path?

        On Sat, 23 Apr 2005 10:20:29 +0200, Fredrik Lundh wrote:[color=blue]
        > 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/pygtk@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 ;-)[/color]

        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.)

        Comment

        Working...