wxPython and PIL

O

Odalrick

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?
 
L

Laszlo Nagy

Odalrick said:
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.SetAlphaData(pil.convert("RGBA").tostring()[3::4])
else:
image = wx.EmptyImage(pil.size[0], pil.size[1])
new_image = pil.convert('RGB')
data = new_image.tostring()
image.SetData(data)
return image

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


Best,

Laszlo
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top