google.appengine.api.images package

Summary

Image manipulation API.

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 a predefined algorithm. The API can also provide information about an image, such as its format, width, height, and a histogram of color values.

Contents

exception google.appengine.api.images.AccessDeniedErrorsource

Bases: google.appengine.api.images.Error

The application does not have permission to access the image.

exception google.appengine.api.images.BadImageErrorsource

Bases: google.appengine.api.images.Error

The image data is corrupt.

exception google.appengine.api.images.BadRequestErrorsource

Bases: google.appengine.api.images.Error

The parameters specified were in some way invalid.

exception google.appengine.api.images.BlobKeyRequiredErrorsource

Bases: google.appengine.api.images.Error

A blob key is required for this operation.

exception google.appengine.api.images.Errorsource

Bases: exceptions.Exception

Base error class for this module.

class google.appengine.api.images.Image(image_data=None, blob_key=None, filename=None)source

Bases: object

Image object to manipulate.

static CheckValidIntParameter(parameter, min_value, max_value, name)source

Checks that a parameter is an integer within the specified range.

crop(left_x, top_y, right_x, bottom_y)source

Crops the image.

The four arguments are the scaling numbers that describe the bounding box that will crop the image. The upper left point of the bounding box will be at (left_x*image_width, top_y*image_height), and the lower right point will be at (right_x*image_width, bottom_y*image_height).

Parameters
  • left_x -- Float value between 0.0 and 1.0, inclusive.

  • top_y -- Float value between 0.0 and 1.0, inclusive.

  • right_x -- Float value between 0.0 and 1.0, inclusive.

  • bottom_y -- Float value between 0.0 and 1.0, inclusive.

Raises
  • TypeError -- If the arguments are not of type float.

  • BadRequestError -- When the bounding box values are invalid or if MAX_TRANSFORMS_PER_REQUEST transforms have already been requested for this image.

execute_transforms(output_encoding=0, quality=None, parse_source_metadata=False, transparent_substitution_rgb=None, rpc=None)source

Performs transformations on a given image.

You can only execute one transformation per image per execute_transforms() call.

Parameters
  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used for JPEG and WEBP quality control.

  • parse_source_metadata -- When True, the metadata (EXIF) of the source image is parsed before any transformations. The results can be retrieved via Image.get_original_metadata.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, transparent pixels will be substituted for the specified color, which must be 32-bit RGB format.

  • rpc -- A UserRPC object.

Returns

A string of the image data after the transformations have been performed on it.

Raises
execute_transforms_async(output_encoding=0, quality=None, parse_source_metadata=False, transparent_substitution_rgb=None, rpc=None)source

Asynchronously performs transformations on a given image.

Parameters
  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used for JPEG & WEBP quality control.

  • parse_source_metadata -- When True, the metadata (EXIF) of the source image is parsed before any transformations. The results can be retrieved via Image.get_original_metadata.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

  • rpc -- A UserRPC object.

Returns

A UserRPC object.

Raises
  • BadRequestError -- When the request specifications are invalid.

  • NotImageError -- When the image data given is not an image.

  • BadImageError -- When the image data given is corrupt.

  • LargeImageError -- When the image data given is too large to process.

  • InvalidBlobKeyError -- When the blob key provided is invalid.

  • TransformationError -- When an error occurs during image manipulation.

  • AccessDeniedError -- When the blob key refers to a Google Storage object, and the application does not have permission to access the object.

  • ValueError -- When transparent_substitution_rgb is not an integer.

  • Error -- All other error conditions.

format

Retrieves the format of the image.

get_original_metadata()source

Lists the metadata of the original image.

Returns a dictionary of metadata extracted from the original image during execute_transform.

ImageWidth and ImageLength fields are corrected if they did not correspond to the actual dimensions of the original image.

Returns

Dictionary of metadata with string keys. If execute_transform was called with parse_metadata set to True, this dictionary contains information about the 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, with least ImageWidth and ImageLength dimensions of the original image being returned.

This call will return None if it is called before a successful execute_transfrom call.

height

Retrieves the height of the image.

histogram(rpc=None)source

Calculates the histogram of the image.

Parameters

rpc -- A UserRPC object.

Returns

3 256-element lists containing the number of occurences of each value of each color in the order RGB. You can learn more about color histograms at Wikipedia.

Raises
  • NotImageError -- When the image data supplied is not an image.

  • BadImageError -- When the image data supplied is corrupt.

  • LargeImageError -- When the image data supplied is too large to process.

  • Error -- All other error conditions.

histogram_async(rpc=None)source

Asynchronously calculates the histogram of the image.

Parameters

rpc -- An optional UserRPC object.

Returns

A UserRPC object.

Return type

rpc

Raises
  • NotImageError -- When the image data supplied is not an image.

  • BadImageError -- When the image data supplied is corrupt.

  • LargeImageError -- When the image data supplied is too large to process.

  • Error -- All other error conditions.

horizontal_flip()source

Flips the image horizontally.

Raises

BadRequestError -- If MAX_TRANSFORMS_PER_REQUEST transforms have already been requested on the image.

im_feeling_lucky()source

Automatically adjusts the image's contrast and color levels.

This is similar to the "I'm Feeling Lucky" button in Picasa.

Raises

BadRequestError -- If MAX_TRANSFORMS_PER_REQUEST transforms have already been requested for this image.

resize(width=0, height=0, crop_to_fit=False, crop_offset_x=0.5, crop_offset_y=0.5, allow_stretch=False)source

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 the image is resized. The maximum dimension allowed for both width and height is 4000 pixels.

If both width and height are specified, and crop_to_fit is True, the less restricting of the two values will be used when the image is resized, and the image will be cropped to fit the specified size. In this case, the center of cropping can be adjusted by crop_offset_x and crop_offset_y.

Parameters
  • width -- Integer of the width in pixels to change the image width to.

  • height -- Integer of the height in pixels to change the image height to.

  • crop_to_fit -- If True, and both width and height are specified, the image is cropped after it is resized to fit the specified dimensions.

  • crop_offset_x -- Float value between 0.0 and 1.0. 0 is left, and 1 is right. The default value is 0.5, or the center of the image.

  • crop_offset_y -- Float value between 0.0 and 1.0. 0 is top, and 1 is bottom. The default value is 0.5, or the center of the image.

  • allow_stretch -- If True, and both width and height are specified, the image is stretched to fit the resize dimensions without maintaining the aspect ratio.

Raises
  • TypeError -- When width or height is not an integer or long type.

  • BadRequestError -- When the height or width is invalid, or if MAX_TRANSFORMS_PER_REQUEST transforms have already been requested on this image.

rotate(degrees)source

Rotates an image a given number of degrees clockwise.

Parameters

degrees -- Integer value of the number of degrees that an image must be rotated. This value must be a multiple of 90.

Raises
  • TypeError -- When degrees is not an integer or long type.

  • BadRequestError -- When the degrees value is invalid or if MAX_TRANSFORMS_PER_REQUEST transforms have already been requested.

set_correct_orientation(correct_orientation)source

Sets a flag to correct the image orientation based on image metadata.

EXIF metadata within the image may contain a parameter that indicates its proper orientation. This value can equal 1 through 8, inclusive. Setting the orientation to 1 means that the image is in its "normal" orientation, i.e., it should be viewed as it is stored. Normally, this orientation value has no effect on the behavior of the transformations. However, if you call this function with the correct_orientation argument, any orientation specified in the EXIF metadata will be corrected during the first transformation.

Whether the correction was requested or not, the orientation value in the transformed image is always cleared to indicate that no additional corrections of the returned image's orientation is necessary.

Parameters

correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE.

Raises

BadRequestError -- If the correct_orientation value is invalid.

vertical_flip()source

Flips the image vertically.

Raises

BadRequestError -- If MAX_TRANSFORMS_PER_REQUEST transforms have already been requested on the image.

width

Retrieves the width of the image.

exception google.appengine.api.images.InvalidBlobKeyError(blob_key=None)source

Bases: google.appengine.api.images.Error

The provided blob key was invalid.

exception google.appengine.api.images.LargeImageErrorsource

Bases: google.appengine.api.images.Error

The image data is too large to process.

exception google.appengine.api.images.NotImageErrorsource

Bases: google.appengine.api.images.Error

The image data given is not recognizable as an image.

exception google.appengine.api.images.ObjectNotFoundErrorsource

Bases: google.appengine.api.images.Error

The blob key referred to an object that does not exist.

exception google.appengine.api.images.TransformationErrorsource

Bases: google.appengine.api.images.Error

An error occurred while attempting to transform the image.

exception google.appengine.api.images.UnsupportedSizeErrorsource

Bases: google.appengine.api.images.Error

The size that was specified is not supported by requested operation.

google.appengine.api.images.composite(inputs, width, height, color=0, output_encoding=0, quality=None, rpc=None)source

Composites one or more images onto a canvas.

Parameters
  • inputs --

    a list of tuples (image_data, x_offset, y_offset, opacity, anchor) where:

    • image_data

      String of the source image data.

    • x_offset

      X offset, in pixels from the anchor position.

    • y_offset

      Y offset, in piyels from the anchor position.

    • opacity

      Opacity of the image, specified as a float in range [0.0, 1.0]

    • anchor

      Anchoring point from ANCHOR_POINTS. The anchor point of the image is aligned with the same anchor point of the canvas. For example, TOP_RIGHT would place the top right corner of the image at the top right corner of the canvas, then apply the x and y offsets.

  • width -- Canvas width, in pixels.

  • height -- Canvas height, in pixels.

  • color -- Canvas background color, encoded as a 32-bit unsigned integer, where each color channel is represented by one byte in ARGB order.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • rpc -- Optional UserRPC object.

Returns

A string that contains the image data of the composited image.

Raises
  • TypeError -- If width, height, color, x_offset or y_offset are not of type integer or long, or if opacity is not a float.

  • BadRequestError -- If more than MAX_TRANSFORMS_PER_REQUEST compositions have been requested, if the canvas width or height is greater than 4000 or less than or equal to 0, if the color is invalid, if the opacity is outside the range [0,1] for any composition option, or if the anchor is invalid.

google.appengine.api.images.composite_async(inputs, width, height, color=0, output_encoding=0, quality=None, rpc=None)source

Asynchronously composites one or more images onto a canvas.

Parameters
  • inputs --

    A list of tuples (image_data, x_offset, y_offset, opacity, anchor), where:

    • image_data

      String of the source image data.

    • x_offset

      X offset, in pixels from the anchor position.

    • y_offset

      Y offset, in piyels from the anchor position.

    • opacity

      Opacity of the image, specified as a float in range [0.0, 1.0]

    • anchor

      Anchoring point from ANCHOR_POINTS. The anchor point of the image is aligned with the same anchor point of the canvas. For example, TOP_RIGHT would place the top right corner of the image at the top right corner of the canvas, then apply the x and y offsets.

  • width -- Canvas width, in pixels.

  • height -- Canvas height, in pixels.

  • color -- Canvas background color, encoded as a 32-bit unsigned integer, where each color channel is represented by one byte in ARGB order.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used for JPEG quality control.

  • rpc -- Optional UserRPC object.

Returns

A UserRPC object.

Raises
  • TypeError -- If width, height, color, x_offset, or y_offset are not an integer or long, or if opacity is not a float.

  • BadRequestError -- If more than MAX_TRANSFORMS_PER_REQUEST compositions have been requested, if the canvas width or height is greater than 4000 or less than or equal to 0, if the color is invalid, if the opacity is outside the range [0,1] for any composition option, or the anchor is invalid.

google.appengine.api.images.create_rpc(deadline=None, callback=None)source

Creates an RPC object for use with the Images API.

Parameters
  • deadline -- Optional deadline in seconds for the operation; the default value is a system-specific deadline (typically 5 seconds).

  • callback -- Optional callable to invoke on completion.

Returns

An apiproxy_stub_map.UserRPC object specialized for this service.

google.appengine.api.images.crop(image_data, left_x, top_y, right_x, bottom_y, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Crops the image.

The four arguments are the scaling numbers that describe the bounding box that will crop the image. The upper left point of the bounding box will be at (left_x*image_width, top_y*image_height), and the lower right point will be at (right_x*image_width, bottom_y*image_height).

Parameters
  • image_data -- String of the source image data.

  • left_x -- Float value between 0.0 and 1.0, inclusive.

  • top_y -- Float value between 0.0 and 1.0, inclusive.

  • right_x -- Float value between 0.0 and 1.0, inclusive.

  • bottom_y -- Float value between 0.0 and 1.0, inclusive.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

Raw image data of the transformed image.

Raises
  • TypeError -- If the arguments are not of type float.

  • BadRequestError -- If the bounding box values are invalid.

  • Error -- All other errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.crop_async(image_data, left_x, top_y, right_x, bottom_y, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Asynchronously crops the given image.

The four arguments are the scaling numbers that describe the bounding box that will crop the image. The upper left point of the bounding box will be at (left_x*image_width, top_y*image_height), and the lower right point will be at (right_x*image_width, bottom_y*image_height).

Parameters
  • image_data -- String of the source image data.

  • left_x -- Float value between 0.0 and 1.0, inclusive.

  • top_y -- Float value between 0.0 and 1.0, inclusive.

  • right_x -- Float value between 0.0 and 1.0, inclusive.

  • bottom_y -- Float value between 0.0 and 1.0, inclusive.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

A UserRPC object; call get_result() to complete the RPC and obtain the crop result.

Raises
  • TypeError -- If the args are not of type float.

  • BadRequestError -- When the bounding box values are invalid.

  • Error -- All other errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.delete_serving_url(blob_key, rpc=None)source

Deletes a serving URL created for blob_key using get_serving_url.

Parameters
  • blob_key -- The BlobKey, BlobInfo, string, or Unicode representation of the BlobKey of a blob with an existing URL that you want to delete.

  • rpc -- Optional UserRPC object.

Raises
google.appengine.api.images.delete_serving_url_async(blob_key, rpc=None)source

Deletes a serving URL created using get_serving_url - async version.

Parameters
  • blob_key -- BlobKey, BlobInfo, string, or unicode representation of the BlobKey of a blob with an existing URL that you want to delete.

  • rpc -- Optional UserRPC object.

Returns

A UserRPC object.

Raises
google.appengine.api.images.get_serving_url(blob_key, size=None, crop=False, secure_url=None, filename=None, rpc=None)source

Obtains a URL that will serve the underlying image.

This URL is served by a high-performance dynamic image serving infrastructure. This URL format also allows dynamic resizing and cropping with certain restrictions. To dynamically resize and crop, specify size and crop arguments, or simply append options to the end of the default URL obtained via this call.

Example:

get_serving_url -> "http://lh3.ggpht.com/SomeCharactersGoesHere"

To get a 32-pixel-sized version (aspect-ratio preserved), append =s32 to the URL:

http://lh3.ggpht.com/SomeCharactersGoesHere=s32

To get a 32-pixel cropped version, append =s32-c:

http://lh3.ggpht.com/SomeCharactersGoesHere=s32-c

Available sizes are any integer in the range [0, 1600] and is available as IMG_SERVING_SIZES_LIMIT.

Parameters
  • blob_key -- The BlobKey, BlobInfo, string, or Unicode representation of BlobKey of the blob whose URL you require.

  • size -- Integer of the size of resulting images.

  • crop -- Boolean value. True requests a cropped image, while False requests a resized image.

  • secure_url -- Boolean value. True requests a https URL, while False requests a http URL.

  • filename -- The file name of a Google Storage object whose URL you require.

  • rpc -- Optional UserRPC object.

Returns

A URL string.

Raises
  • BlobKeyRequiredError -- If a blob key was not specified in the constructor.

  • UnsupportedSizeError -- If you specified an invalid size parameter.

  • BadRequestError -- If crop and size are present in the wrong combination, or if blob_key and filename are both specified.

  • TypeError -- If secure_url is not a boolean type.

  • AccessDeniedError -- If blob_key refers to a Google Storage object and the application does not have permission to access the object.

  • ObjectNotFoundError -- If blob_key refers to an object that doesn't exist.

google.appengine.api.images.get_serving_url_async(blob_key, size=None, crop=False, secure_url=None, filename=None, rpc=None)source

Asynchronously obtains a URL that will serve the underlying image.

This URL is served by a high-performance dynamic image serving infrastructure. This URL format also allows dynamic resizing and cropping with certain restrictions. To dynamically resize and crop, specify size and crop arguments, or simply append options to the end of the default URL obtained via this call.

Example:

get_serving_url -> "http://lh3.ggpht.com/SomeCharactersGoesHere"

To get a 32-pixel-sized version (aspect-ratio preserved), append =s32 to the URL:

http://lh3.ggpht.com/SomeCharactersGoesHere=s32

To get a 32-pixel cropped version, append =s32-c:

http://lh3.ggpht.com/SomeCharactersGoesHere=s32-c

Available sizes are any integer in the range [0, 1600] and is available as IMG_SERVING_SIZES_LIMIT.

Parameters
  • blob_key -- The BlobKey, BlobInfo, string, or Unicode representation of the BlobKey of blob whose URL you require.

  • size -- Integer of the size of resulting images.

  • crop -- Boolean value. True requests a cropped image, while False requests a resized image.

  • secure_url -- Boolean value. True requests a https URL, while False requests a http URL.

  • filename -- The file name of a Google Storage object whose URL you require.

  • rpc -- Optional UserRPC object.

Returns

A UserRPC whose result will be a string that is the serving URL.

Raises
  • BlobKeyRequiredError -- If a blob key was not specified in the constructor.

  • UnsupportedSizeError -- If you specified an invalid size parameter.

  • BadRequestError -- If crop and size are present in the wrong combination, or if blob_key and filename are both specified.

  • TypeError -- If secure_url is not a boolean type.

  • AccessDeniedError -- If blob_key refers to a Google Storage object and the application does not have permission to access the object.

google.appengine.api.images.histogram(image_data, rpc=None)source

Calculates the histogram of the given image.

Parameters
  • image_data -- String of the source image data.

  • rpc -- An optional UserRPC object.

Returns

3 256-element lists containing the number of occurences of each value of each color in the order RGB.

Raises
google.appengine.api.images.histogram_async(image_data, rpc=None)source

Calculates the histogram of the given image - async version.

Parameters
  • image_data -- String of the source image data.

  • rpc -- An optional UserRPC object.

Returns

An UserRPC object.

Raises
google.appengine.api.images.horizontal_flip(image_data, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Flips the image horizontally.

Parameters
  • image_data -- String of the source image data.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

Raw image data of the transformed image.

Raises

Error -- All errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.horizontal_flip_async(image_data, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Asynchronously flips the image horizontally.

Parameters
  • image_data -- String of the source image data.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

A UserRPC object; call get_result() to complete the RPC and obtain the crop result.

Raises

Error -- All errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.im_feeling_lucky(image_data, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Automatically adjusts image levels.

This is similar to the "I'm Feeling Lucky" button in Picasa.

Parameters
  • image_data -- String of the source image data.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

Raw image data of the transformed image.

Raises

Error -- All errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.im_feeling_lucky_async(image_data, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Asynchronously automatically adjusts image levels.

This is similar to the "I'm Feeling Lucky" button in Picasa.

Parameters
  • image_data -- String of the source image data.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

A UserRPC object.

Raises

Error -- All errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.resize(image_data, width=0, height=0, output_encoding=0, quality=None, correct_orientation=0, crop_to_fit=False, crop_offset_x=0.5, crop_offset_y=0.5, allow_stretch=False, rpc=None, transparent_substitution_rgb=None)source

Resizes a given image file while maintaining the aspect ratio.

If both width and height are specified, the more restricting of the two values will be used when resizing the image. The maximum dimension allowed for both width and height is 4000 pixels.

If both width and height are specified and crop_to_fit is True, the less restricting of the two values will be used when resizing and the image will be cropped to fit the specified size. In this case, the center of cropping can be adjusted by crop_offset_x and crop_offset_y.

Parameters
  • image_data -- String of the source image data.

  • width -- Integer of the width (in pixels) to change the image width to.

  • height -- Integer of the height (in pixels) to change the image height to.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • crop_to_fit -- If True, and both width and height are specified, the image is cropped after being resized to fit the specified dimensions.

  • crop_offset_x -- Float value between 0.0 and 1.0. 0 is left and 1 is right. The default value is 0.5, or the center of image.

  • crop_offset_y -- Float value between 0.0 and 1.0. 0 is top and 1 is bottom. The default value is 0.5, or the center of image.

  • allow_stretch -- If True, and both width and height are specified, the image is stretched to fit the resized dimensions without maintaining the aspect ratio.

  • rpc -- Optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

Raw image data of the resized image.

Raises
  • TypeError -- When width or height are not of integer or long type.

  • BadRequestError -- When the specified width or height is invalid.

  • Error -- All other errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.resize_async(image_data, width=0, height=0, output_encoding=0, quality=None, correct_orientation=0, crop_to_fit=False, crop_offset_x=0.5, crop_offset_y=0.5, allow_stretch=False, rpc=None, transparent_substitution_rgb=None)source

Asynchronously resizes an image file, maintaining the aspect ratio.

If both width and height are specified, the more restricting of the two values will be used when resizing the image. The maximum dimension allowed for both width and height is 4000 pixels.

If both width and height are specified and crop_to_fit is True, the less restricting of the two values will be used when resizing and the image will be cropped to fit the specified size. In this case, the center of cropping can be adjusted by crop_offset_x and crop_offset_y.

Parameters
  • image_data -- String of the source image data.

  • width -- Integer of the width in pixels to change the image width to.

  • height -- Integer of the height in pixels to change the image height to.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • crop_to_fit -- If True, and both width and height are specified, the image is cropped after being resized to fit the specified dimensions.

  • crop_offset_x -- Float value between 0.0 and 1.0. 0 is left and 1 is right. The default value is 0.5, or the center of image.

  • crop_offset_y -- Float value between 0.0 and 1.0. 0 is top and 1 is bottom. The default value is 0.5, or the center of image.

  • allow_stretch -- If True, and both width and height are specified, the image is stretched to fit the resized dimensions without maintaining the aspect ratio.

  • rpc -- Optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

A UserRPC object; call get_result() to obtain the result of the RPC.

Raises
  • TypeError -- When width or height are not of integer or long type.

  • BadRequestError -- When the specified width or height is invalid.

  • Error -- All other errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.rotate(image_data, degrees, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Rotates an image a given number of degrees clockwise.

Parameters
  • image_data -- String of the source image data.

  • degrees -- A value from ROTATE_DEGREE_VALUES.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

Raw image data of the rotated image.

Raises
  • TypeError -- When degrees is not of integer or long type.

  • BadRequestError -- When the specified degrees value is invalid.

  • Error -- All other errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.rotate_async(image_data, degrees, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Asynchronously rotates an image a specified number of degrees clockwise.

Parameters
  • image_data -- String of the source image data.

  • degrees -- A value from ROTATE_DEGREE_VALUES.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

A UserRPC object; call get_result() to complete the RPC and obtain the crop result.

Raises
  • TypeError -- When degrees is not of integer or long type.

  • BadRequestError -- When the specified degrees value is invalid.

  • Error -- All other errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.vertical_flip(image_data, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Flips the image vertically.

Parameters
  • image_data -- String of the source image data.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

Raw image data of the transformed image.

Raises

Error -- All errors. See Image.ExecuteTransforms for more details.

google.appengine.api.images.vertical_flip_async(image_data, output_encoding=0, quality=None, correct_orientation=0, rpc=None, transparent_substitution_rgb=None)source

Asynchronously flips the image vertically.

Parameters
  • image_data -- String of the source image data.

  • output_encoding -- A value from OUTPUT_ENCODING_TYPES.

  • quality -- A value between 1 and 100 to specify the quality of the encoding. This value is only used to control JPEG quality.

  • correct_orientation -- A value from ORIENTATION_CORRECTION_TYPE to indicate if orientation correction should be performed during the transformation.

  • rpc -- An optional UserRPC object.

  • transparent_substitution_rgb -- When transparent pixels are not supported in the destination image format, then transparent pixels will be substituted for the specified color, which must be in 32-bit RGB format.

Returns

A UserRPC object; call get_result() to complete the RPC and obtain the crop result.

Raises

Error -- All errors. See Image.ExecuteTransforms for more details.

Send feedback about...

App Engine standard environment for Python