Imagin documentation

Imagin is a simple web service for processing and generating images. It understands a very basic text-based language describing transformations to apply to images.

Interface

To call Imagin, send an HTTP POST to http://imagin.notdot.net/do. The body of the post should be of mime-type multipart/form-data, and contain at least one form element, called "code", containing the Imagin script to execute. It may also contain any number of additional fields containing images for the script to use; these will be added as variables before the script begins executing.

If an error occurs, Imagin will return an HTTP 400 or 500 response, with relevant text explaining the error.

If your script contains an 'output' op, Imagin will return an HTTP 200 response, with the generated image, with the content-type set appropriately to the type of image you requested.

Otherwise, Imagin will return an HTTP 200 response indicating image processing succeeded.

Language

Imagin accepts a very simple text-based language describing image operations to perform. Each command is on its own line, and consists of a function name, followed by one or more arguments, all space-separated. Typically, the first argument is a return paramter, to which the result of the operation will be assigned.

For example, the following command crops out a 200x200 segment of the image 'img' and stores it in 'out':

crop out img 200 200 100 100

Functions

new <dest> <mode> <width> <height>

Creates a new, uninitialized canvas in dest with the specified width and height. mode is any valid mode defined by PIL, such as "RGB" or "RGBA".

fetch <dest> <url>

Fetches the provided image URL and stores it to dest.

paste <dest> <src> <x> <y>

Pastes the contents of src into dest, starting at the specified coordinates.

resize <dest> <src> <width> <height>

Sets dest to src resized to the specified width and height.

crop <dest> <src> <x> <y> <width> <height>

Sets dest to a cropped section of src

output <image> <format>

Outputs image to the browser in the specified format and terminates execution. format may be any image format supported by PIL.

spritecut <prefix> <src> <width> <height> <gap_x> <gap_y>

Cuts up src into rectangular sections of the specified width and height, with (gap_x, gap_y) pixels between each sprite, and stores them in image variables of the form prefix.num, where num is the number of the sprite, starting at 0 and counting left to right, top to bottom.

For example, cutting up a 300x100 image with the command sprite dest src 100 50 would yield 6 output images, named dest.0, dest.1, ..., dest.5 corresponding to the 6 100x50 rectangular sections of the image.

spritepaste <dest> <prefix> <width> <height> <data>

Pastes a series of sprites into dest.

This command pastes a series of sprites into dest, starting at the top-left corner, and proceeding left to right, top to bottom, in units of the specified width and height. The sprite to paste is described by the corresponding character in data, using the 'simple encoding' specified by the Google Chart API.

For example, spritepaste dest s 16 16 "BADA", where dest is a 32x32 image, would paste the 16x16 images s.1, s.0, s.3 and s.0 into the top left, top right, bottom left and bottom right corners of dest, respectively.

spritepaste2 <dest> <prefix> <width> <height> <data>

Pastes a series of sprites into dest.

This command pastes a series of sprites into dest, starting at the top-left corner, and proceeding left to right, top to bottom, in units of the specified width and height. The sprite to paste is described by the corresponding characters in data, using the 'extended encoding' specified by the Google Chart API.

For example, spritepaste dest s 16 16 "ABAAADAA", where dest is a 32x32 image, would paste the 16x16 images s.1, s.0, s.3 and s.0 into the top left, top right, bottom left and bottom right corners of dest, respectively.

s3send <image> <format> <pubkey> <privkey> <bucket> <path> <acl>

Uploads image to Amazon's S3 service into the specified bucket and path. pubkey and privkey should be the AWS public key and secret access key. ACL should be the 'canned' ACL to set on the new item, or an empty string ("") to leave it at the default.

thumbnail <image> <width> <height>

Resizes image to have maximum dimensions of widthxheight. This modifies the image in-place.

convert <dest> <src> <mode>

Converts src to color mode mode and stores the result in dest.