Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
App Engine provides the ability to manipulate image data using a dedicated Images service. The Images service can resize, rotate, flip, and crop images; it can composite multiple images into a single image; and it can convert image data between several formats. It can also enhance photographs using an predefined algorithm. The API can also provide information about an image, such as its format, width, height, and a histogram of color values.
The Images service can accept image data directly from the app, or it can use a Blobstore value. When the source is the Blobstore, the size of the image to transform can be up to the maximum size of a Blobstore value. However, the transformed image is returned directly to the app, and so must be no larger than 1 megabyte. This is potentially useful for making thumbnail images of photographs uploaded to the Blobstore by users.
The Image service Java API lets you apply transformations to images, using a service instead of performing image processing on the application server. The app prepares an Image object with the image data to transform, and a Transform object with instructions on how to transform the image. The app gets an ImagesService object, then calls its applyTransform() method with the Image and the Transform objects. The method returns an Image object of the transformed image.
The app gets ImagesService, Image and Transform instances using the ImagesServiceFactory.
import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.images.Transform;
// ...
byte[] oldImageData; // ...
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image oldImage = ImagesServiceFactory.makeImage(oldImageData);
Transform resize = ImagesServiceFactory.makeResize(200, 300);
Image newImage = imagesService.applyTransform(resize, oldImage);
byte[] newImageData = newImage.getImageData();
Multiple transforms can be combined into a single action using a CompositeTransform instance. See the images API reference.
The Images service can resize, rotate, flip, and crop images, and enhance photographs. It can also composite multiple images into a single image.
You can resize the image while maintaining the same aspect ratio.

You can rotate the image in 90 degree increments.

You can flip the image horizontally.

You can flip the image vertically.

You can crop the image with a given bounding box.

The "I'm Feeling Lucky" transform enhances dark and bright colors in an image and adjusts both color and contrast to optimal levels.

The service accepts image data in the JPEG, PNG, GIF (including animated GIF), BMP, TIFF and ICO formats.
It can return transformed images in the JPEG and PNG formats. If the input format and the output format are different, the service converts the input data to the output format before performing the transformation.
The Images service can use a value from the Blobstore as the source for a transformation. An image from the Blobstore can be as large as the maximum size of a Blobstore value. Note, however, that the result of the transformation is returned directly to the app, and must therefore not exceed the API response limit of 1 megabyte. You can use this to make thumbnail images of photographs uploaded by users.
To transform an image from the Blobstore in Java, you create the Image object by calling the static method ImageServiceFactory.makeImageFromBlob(), passing it a blobstore.BlobKey value. The rest of the API behaves as expected. The applyTransform() method returns the result of the transforms, or throws an ImageServiceFailureException if the result is larger than the maximum size of 1 megabyte.
import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.images.Transform;
// ...
BlobKey blobKey; // ...
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
Transform resize = ImagesServiceFactory.makeResize(200, 300);
Image newImage = imagesService.applyTransform(resize, oldImage);
byte[] newImageData = newImage.getImageData();
The development server uses your local machine to perform the capabilities of the Images service.
The Java development server includes functionality to simulate the Image service. The "I'm Feeling Lucky" photo enhancement feature is not supported.
Each Images service request counts toward the Image Manipulation API Calls quota. An app can perform multiple transformations of an image in a single API call.
Data sent to the Images service counts toward the Data Sent to (Images) API quota. Data received from the Images service counts toward the Data Received from (Images) API quota.
Each transformation of an image counts toward the Transformations Executed quota.
For more information on quotas, see Quotas, and the "Quota Details" section of the Admin Console.
In addition to quotas, the following limits apply to the use of the Images service:
| Limit | Amount |
|---|---|
| maximum data size of image sent to service | 1 megabyte |
| maximum data size of image received from service | 1 megabyte |