469,348 Members | 1,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,348 developers. It's quick & easy.

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?

Oct 19 '06 #1
2 7958
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
Thanks for the answer.

Oct 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by SeeBelow | last post: by
25 posts views Thread by BJörn Lindqvist | last post: by
1 post views Thread by timothy.williams | last post: by
1 post views Thread by James Stroud | last post: by
22 posts views Thread by Glurt Wuntal | last post: by
reply views Thread by Robin Dunn | last post: by
reply views Thread by Robin Dunn | last post: by
reply views Thread by Robin Dunn | last post: by
4 posts views Thread by stef | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.