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

wxPython and PIL

P: n/a
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?

Oct 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.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

Oct 19 '06 #2

P: n/a
Thanks for the answer.

Oct 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.