Around the houses, App Engine stylee
I'm quite aware of the depths of my e-stupidity, but the only way I could get an image out of an email attachment sent to a Google App Engine app and uploaded to S3 using Boto, was this absurd backflip (literally).
class LogSenderHandler(InboundMailHandler): def receive(self, message): attachments = [] if message.attachments: if isinstance(message.attachments[0], basestring): attachments = [message.attachments] else: attachments = message.attachments for filename, content in attachments: img = images.Image(content.decode()) if img: img.rotate(360) sitehelpers.upload_to_s3(filename, StringIO(img.execute_transforms(output_encoding=images.JPEG)), message.sender)
Anybody out there in the land of tWeb is welcome to call me on this, but in case you are struggling and need any solution possible, this works a treat for me. Ask Jeremy Clarkson about performance.
5 comments
Effisfor said...
I like to think in all my naivety, that a computer won't have a little hamster rotating a canvas and taking a photo of it at the end, so 0 or 360 should be the same. Maybe I need to talk to Richard Hammond.
Feb 17, 2010
Mase said...
Witty. I just wondered if maybe Appengine would short circuit the transformation if the angle was zero and so save you $0.000000001 per image. Infact, have you tried it without even giving it a transformation to do? Wouldn't be surprised if that worked. I think that's how James May does it on his blog.
Effisfor said...
You have to have transformations in the can for the apply transformations method to fire. Even Tiff Needell knows these things.Try it yourself. You can download the SDK here: http://code.google.com/appengine
Feb 17, 2010
Robin Houston said...
This has got nothing to do with S3, right? You just need a way to convert various types of image into JPEG?If I got that right, I think you're totally on the money. I can't see any better way of using the app engine images API to do this without making some null transformation. Very strange.