Sometimes I have to put text on a path

Sunday, July 10, 2011

Image Python API and Google app engine; modified Guestbook-hello application with images API;Python Imaging Library

1) Images Python API Overview:
http://code.google.com/appengine/docs/python/images/overview.html

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.
The Images service can accept image data directly from the app, or it can use a Blobstore value (http://code.google.com/appengine/docs/python/blobstore/). 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 32 megabytes (this is potentially useful for making thumbnail images of photographs uploaded to the Blobstore by users).

2)Download and install
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.
The Python development server uses the Python Imaging Library (PIL) to simulate the Image service. This library is not included with the Python standard library or the SDK, and must be installed separately. See Installing PIL: http://code.google.com/appengine/docs/python/images/installingPIL.html
The WEBP image format is only supported if a suitable PIL decoder plugin has been installed.


The Images service can 1)resize (resize the image while maintaining the same aspect ratio), 2)rotate, 3)flip, 4)crop images, and 5)enhance photographs (The "I'm Feeling Lucky" transform enhances dark and bright colors in an image and adjusts both color and contrast to optimal levels). It can also composite multiple images into a single image.

The service accepts image data in the JPEG, PNG, WEBP, GIF (including animated GIF), BMP, TIFF and ICO formats. It can return transformed images in the JPEG, WEBP 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.

To install PIL on Mac OS X 10.4 and higher (http://code.google.com/appengine/docs/python/images/installingPIL.html):
Download the PIL .dmg file. For example, you can download the PIL 1.1.6 .dmg file from http://pythonmac.org/packages/py25-fat/index.html
Double-click on the installer to start the installation process.
Choose the correct directory.
Finish the installation.
---------------------------
3)Using the Images Python API
http://code.google.com/appengine/docs/python/images/usingimages.html

3-a) Creating a image property AND Uploading User Images:
The first thing we need to do is update the model from the guestbook sample (http://ex-ample.blogspot.com/2011/07/first-steps-google-appengine-mac.html and http://ex-ample.blogspot.com/2011/07/hello-with-google-app-engine-and-webapp.html) to store the uploaded image as a blob.

3-b) composite image from multiple images: http://code.google.com/appengine/docs/python/images/functions.html
The format of the final composite image, either PNG or JPEG. The default is PNG.


Image is provided by the google.appengine.api.images module:
http://code.google.com/appengine/docs/python/images/imageclass.html
Image()
Properties:

  • width
  • height

Instance methods:

  • crop()
  • execute_transforms()
  • histogram()
  • horizontal_flip()
  • im_feeling_lucky()
  • resize()
  • rotate()
  • vertical_flip()

1 comment: