English
Skip to page content Skip to main navigation

e.g. "templates" or "datastore"

# Functions

The `google.appengine.api.images` package provides the following functions:

resize(image_data, width=0, height=0, output_encoding=images.PNG)

  Resizes an image, scaling down or up to the given width and height. The function takes the image data to resize, and returns the transformed image in the same format.

  Arguments:

  image_data
    The image to resize, as a bytestring (`str`) in JPEG, PNG, GIF (including animated), BMP, TIFF, or ICO format.
  width
    The desired width, as a number of pixels. Must be an `int` or `long`.
  height
    The desired height, as a number of pixels. Must be an `int` or `long`.
  output_encoding
    The desired format of the transformed image. This is either `images.PNG` or `images.JPEG`. The default is `images.PNG`.
crop(image_data, left_x, top_y, right_x, bottom_y), output_encoding=images.PNG)

  Crops an image to a given bounding box. The function takes the image data to crop, and 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:

  image_data
    The image to crop, as a bytestring (`str`) in JPEG, PNG, GIF (including animated), BMP, TIFF, or ICO format.
  left_x
    The left border of the bounding box, as a proportion of the image width specified as a `float` value from 0.0 to 1.0 (inclusive).
  top_y
    The top border of the bounding box, as a proportion of the image height specified as a `float` value from 0.0 to 1.0 (inclusive).
  right_x
    The right border of the bounding box, as a proportion of the image width specified as a `float` value from 0.0 to 1.0 (inclusive).
  bottom_y
    The bottom border of the bounding box, as a proportion of the image height specified as a `float` value from 0.0 to 1.0 (inclusive).
  output_encoding
    The desired format of the transformed image. This is either `images.PNG` or `images.JPEG`. The default is `images.PNG`.
rotate(image_data, degrees, output_encoding=images.PNG)

  Rotates an image. The amount of rotation must be a multiple of 90 degrees. The function takes the image data to rotate, and returns the transformed image in the same format.

  Rotation is performed clockwise. A 90 degree turn rotates the image so that the edge that was the top becomes the right edge.

  Arguments:

  image_data
    The image to rotate, as a bytestring (`str`) in JPEG, PNG, GIF (including animated), BMP, TIFF, or ICO format.
  degrees
    The amount to rotate the image, as a number of degrees, in multiples of 90 degrees.
  output_encoding
    The desired format of the transformed image. This is either `images.PNG` or `images.JPEG`. The default is `images.PNG`.
horizontal_flip(image_data, output_encoding=images.PNG)

  Flips an image horizontally. The edge that was the left becomes the right edge, and vice versa. The function takes the image data to flip, and returns the transformed image in the same format.

  Arguments:

  image_data
    The image to flip, as a bytestring (`str`) in JPEG, PNG, GIF (including animated), BMP, TIFF, or ICO format.
  output_encoding
    The desired format of the transformed image. This is either `images.PNG` or `images.JPEG`. The default is `images.PNG`.
vertical_flip(image_data, output_encoding=images.PNG)

  Flips an image vertically. The edge that was the top becomes the bottom edge, and vice versa. The function takes the image data to flip, and returns the transformed image in the same format.

  Arguments:

  image_data
    The image to flip, as a bytestring (`str`) in JPEG, PNG, GIF (including animated), BMP, TIFF, or ICO format.
  output_encoding
    The desired format of the transformed image. This is either `images.PNG` or `images.JPEG`. The default is `images.PNG`.
im_feeling_lucky(image_data, output_encoding=images.PNG)

  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 function takes the image data to adjust, and returns the transformed image in the same format.

  Arguments:

  image_data
    The image to adjust, as a bytestring (`str`) in JPEG, PNG, GIF (including animated), BMP, TIFF, or ICO format.
  output_encoding
    The desired format of the transformed image. This is either `images.PNG` or `images.JPEG`. The default is `images.PNG`.

  Note: The `im_feeling_lucky()` method is no-op when used locally in the SDK as there is no equivilent method in PIL.

histogram(image_data)

  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.

composite(inputs, width, height, color=0, output_encoding=PNG)

  Produces a composite image from multiple images.

  Arguments:

  inputs

    The images to use in the composite, as a list of tuples. Each tuple must contain 5 elements:

    - the image data, as a byte string (`str`)
    - the x offset from the anchor position to place the image in the canvas, as a number of pixels (possibly negative)
    - the y offset from the anchor position to place the image in the canvas, as a number of pixels (possibly negative)
    - the opacity of the image, as a floating point number between 0.0 and 1.0 inclusive
    - the position of the anchor in the canvas, one of the following: `TOP_LEFT` `TOP_CENTER` `TOP_RIGHT` `CENTER_LEFT` `CENTER_CENTER` `CENTER_RIGHT` `BOTTOM_LEFT` `BOTTOM_CENTER` `BOTTOM_RIGHT`

    The images are composited in the order they appear in the list, with the first image applied first ("below" the other images).

  width
    The width of the composite image's canvas, as a number of pixels.
  height
    The height of the composite image's canvas, as a number of pixels.
  color
    The background color of the composite image's canvas, as a 32-bit unsigned integer where each color channel is represented by one byte, in the order of alpha channel, red, green then blue. The default is 0 (black).
  output_encoding
    The format of the final composite image, either `PNG` or `JPEG`. The default is `PNG`.

  Returns the composite image data as a byte string in the requested format.