Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
An instance of the Image class represents a single image to which multiple transformations can be applied. Methods on the instance set up transformations, which are executed all at once when the execute_transforms()
method is called.
Image
is provided by the google.appengine.api.images
module.
The Image class is used to encapsulate image information and transformations for that image.
After one or more transforms is called on an image object, you can execute the transforms with execute_transforms() method.
Note: Each transform is applied in the order requested and can only be called once per image per execute_transforms()
call.
The Image constructor takes the data of the image to transform as a bytestring (the image_data argument) or the BlobKey of a Blobstore value, or a BlobInfo object to use as the image to transform. Only one of these should be provided.
An image to be transformed.
Arguments:
str
). The image data can be encoded in JPEG, PNG, WEBP, GIF (including animated), BMP, TIFF, or ICO format. An Image instance has the following properties:
width
The width of the image, in pixels.
height
The height of the image, in pixels.
format
The format of the image. The supported image formats are:
images.JPEG
images.PNG
images.WEBP
images.BMP
images.GIF
images.ICO
images.TIFF
An Image instance has the following methods:
Crops an image to a given bounding box. The method returns the transformed image in the same format.
The left, top, right and bottom of the bounding box are specified as proportional distances. The coordinates of the bounding box are determined as left_x * width
, top_y * height
, right_x * width
and bottom_y * height
. This allows you to specify the bounding box independently of the final width and height of the image, which may change simultaneously with a resize action.
Arguments:
float
value from 0.0 to 1.0 (inclusive).float
value from 0.0 to 1.0 (inclusive).float
value from 0.0 to 1.0 (inclusive).float
value from 0.0 to 1.0 (inclusive).Executes all transforms set for the Image instance by the above methods, modifying the image in-place, and returns the image's encoded representation as a string. In case of an error, the API raises a BadRequestError.
Arguments:
images.PNG
, images.WEBP
or images.JPEG
. The default is images.PNG
.
+ Note: The images.WEBP
argument is not supported in the SDK without a WEBP PIL decoder plug-in installed.
Note: The quality
argument is not supported in the SDK.
Gets the metadata from the original image.
Note: Some of the EXIF fields are processed. For example, fields with multiple values are returned as lists, rational types are returned as floats, and GPS coordinates are already parsed to signed floats. ImageWidth and ImageLength fields are corrected if they did not correspond to the actual dimensions of the original image.
Returns a dictionary with string keys. If execute_transform was called with parse_metadata=True, this dictionary contains information about various properties of the original image, such as dimensions, color profile, and properties from EXIF. Even if parse_metadata was False or the images did not have any metadata, the dictionary will contain a limited set of metadata, at least 'ImageWidth' and 'ImageLength', corresponding to the dimensions of the original image. Returns None if called before a successful execute_transfrom.
In the development web server, this method supports only a very limited set of EXIF fields. Production will return much more data then the local development server.
Calculates a histogram of the image's color values.
The return value is a list of 3 lists of value totals for red, green and blue, respectively. Each color list contains an occurrence count for each of 256 color values, ordered by color value (the 0th element contains a count of occurrences for the value 0, the 255th element a count of the value 255).
Flips an image horizontally. The edge that was the left becomes the right edge, and vice versa.
Adjusts the contrast and color levels of an image according to an algorithm for improving photographs. This is similar to the "I'm Feeling Lucky" feature of Google Picasa. The method returns the transformed image in the same format.
Note: The im_feeling_lucky()
method is no-op when used locally in the SDK as there is no equivalent method in PIL.
Resizes an image, scaling down or up to the given width and height. The resize transform preserves the aspect ratio of the image. If both the width and the height arguments are provided, the transform uses the dimension that results in a smaller image.
Arguments:
int
or long
.int
or long
.Rotates an image. The amount of rotation must be a multiple of 90 degrees.
Rotation is performed clockwise. A 90 degree turn rotates the image so that the edge that was the top becomes the right edge.
Arguments:
int
or long
.Flips an image vertically. The edge that was the top becomes the bottom edge, and vice versa.