Google Code offered in: 中文 - English - Português - Pусский - Español - 日本語
The App Engine image service lets your application manipulate images using the same scalable infrastructure as Picasa Web Albums. With this API, you can resize, crop, rotate and flip images in JPEG, PNG, GIF (including animated), BMP, TIFF, and ICO formats as well as adjust their contrast and color levels using an automated algorithm for correcting photographs.
Transformations can be performed on an image to produce thumbnails, and other typical operations done in the course of application management.
The current transformations available are:
Resizes the image maintaining the aspect ratio. If both width and height are specified, the more restricting of the two values will be used when resizing the photo.
Rotates an image a given number of degrees clockwise.
Flips the image horizontally.
Flips the image vertically.
Crops the image based on a bounding box you pass into the function.
The "I'm Feeling Lucky" transform enhances dark and bright colors in an image and adjusts both color and contrast to optimal levels.
Note: In order to use the Images API in your local environment you must first download and install PIL, the Python Imaging Library. PIL is not available on App Engine; it is only used as a stub for the Images API in your local environment. Only the transforms provided in the images API are available on App Engine.
from google.appengine.api import images from google.appengine.ext import db from google.appengine.ext import webapp class Photo(db.Model): title = db.StringProperty() full_size_image = db.BlobProperty() class Thumbnailer(webapp.RequestHandler): def get(self): if self.request.get("id"): photo = Photo.get_by_id(self.request.get("id")) if photo: img = images.Image(photo.full_size_image) img.resize(width=80, height=100) img.im_feeling_lucky() thumbnail = img.execute_transforms(output_encoding=images.JPEG) self.response.headers['Content-Type'] = 'image/jpeg' self.response.out.write(thumbnail) return # Either "id" wasn't provided, or there was no image with that ID # in the datastore. self.error(404)