Skip to page content Skip to main navigation
English | Site Directory

e.g. "templates" or "datastore"

# Overview

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:

#### Resize

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.

#### Rotate

Rotates an image a given number of degrees clockwise.

#### Horizontal Flip

Flips the image horizontally.

#### Vertical Flip

Flips the image vertically.

#### Crop

Crops the image based on a bounding box you pass into the function.

#### I'm Feeling Lucky.

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)