wxPython and PIL

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

    #1

    wxPython and PIL

    I'm making a simple program to crop and scale images, essentially make
    thumbnails from a user defined subset of the image.

    I'm planning to use Python Image Library to crop and resize the images,
    mostly to make the resized smaller images look good.

    How do I display a PIL image with wxPython?

  • Laszlo Nagy

    #2
    Re: wxPython and PIL

    Odalrick wrote:
    I'm making a simple program to crop and scale images, essentially make
    thumbnails from a user defined subset of the image.
    >
    I'm planning to use Python Image Library to crop and resize the images,
    mostly to make the resized smaller images look good.
    >
    How do I display a PIL image with wxPython?
    >
    >
    def piltoimage(pil, alpha=True):
    """Convert PIL Image to wx.Image."""
    if alpha:
    image = apply( wx.EmptyImage, pil.size )
    image.SetData( pil.convert( "RGB").tostring () )
    image.SetAlphaD ata(pil.convert ("RGBA").tostri ng()[3::4])
    else:
    image = wx.EmptyImage(p il.size[0], pil.size[1])
    new_image = pil.convert('RG B')
    data = new_image.tostr ing()
    image.SetData(d ata)
    return image

    def imagetopil(imag e):
    """Convert wx.Image to PIL Image."""
    pil = Image.new('RGB' , (image.GetWidth (), image.GetHeight ()))
    pil.fromstring( image.GetData() )
    return pil


    Best,

    Laszlo

    Comment

    • Odalrick

      #3
      Re: wxPython and PIL

      Thanks for the answer.

      Comment

      Working...