views:

236

answers:

3

I'm on the google appengine, and trying to resize images. I do :

from google.appengine.api import images
image = images.resize(contents, w, h)

And for some images I get a nice transparent resize, and others I get a black background.

How can I keep the transparency for all images?

+1  A: 

Article on this problem: http://doesnotvalidate.com/2009/resizing-transparent-images-with-django-pil/ Google-code patch: http://code.google.com/p/sorl-thumbnail/issues/detail?id=56

Nathan Ross Powell
That looks like a django thumbnail application. Can I use PIL directly on app-engine?
Paul Tarjan
I've tried, and I can't use PIL in app-engine. Do you have a pure python implementation?
Paul Tarjan
A: 

Is this on the dev appserver, or in production? There's a known bug on the dev appserver that turns transparent to black when compositing, but it should run fine in production.

Nick Johnson
Production. Dev works perfectly : http://paulisageek.com:4266/gartoon/application/rtf?size=64
Paul Tarjan
A: 

With PIL you have to convert your image in RGBA like this :

im = im.convert("RGBA")

If you want a better implementation, you can read the sorl-thumbnail code. It makes a good usage of PIL.

Natim
I wish I had real PIL on the appengine :(
Paul Tarjan
The question is why are you using appengine instead of PIL ?I am quite sure that appengine use PIL so ...
Natim
I don't know what they use underneath, but `import PIL` doesn't work, nor do they expose any function to do what you recommend. (and they won't let me ship them PIL because it has compiled C code)
Paul Tarjan
`import Imaging` and not PIL
Natim
On appengine: <type 'exceptions.ImportError'>: No module named ImagingTraceback (most recent call last): File "/base/data/home/apps/openicon/1.337362201776746924/main.py", line 8, in <module> import Imaging
Paul Tarjan
Imaging is PIL not appengine !!!
Natim