©2009 Google -
Code Home -
Terms of Service -
Privacy Policy -
Site Directory
Google Code offered in:
English -
Español -
日本語 -
한국어 -
Português -
Pусский -
中文(简体) -
中文(繁體)
The Canvas module provides an image manipulation API to JavaScript.
The Canvas module is a graphics API that is inspired by the HTML5 canvas, with additional methods to decode from and encode to binary formats (such as PNG and JPEG), represented by Blobs.
A Gears Canvas is not yet a complete implementation of the HTML5 canvas specification, and there are two significant differences:
getContext, and in particular
does not provide a 2D context.This API requires user permission. If you would like to customize the default dialog, you can explicitly call google.gears.factory.getPermission() - see how.
readwrite attribute int height
readwrite attribute int width
void crop(x, y, w, h)
void decode(blob)
Blob encode([mimeType, options])
void resize(w, h, [filter])
| Attribute | Type | Description |
|---|---|---|
| height | readwrite attribute int | The height of the Canvas. The default value is 150. |
| width | readwrite attribute int | The width of the Canvas. The default value is 300. |
void crop(x, y, w, h) |
|
|---|---|
| Summary: | Crops the Canvas. The crop happens "in-place", as opposed to returning a new Canvas. |
| Parameters: |
x - The left co-ordinate of the crop rectangle.
y - The top co-ordinate of the crop rectangle.
w - The width of the crop rectangle.
h - The height of the crop rectangle.
|
void decode(blob) |
|
|---|---|
| Summary: | Loads an image into this Canvas, replacing the Canvas' current dimensions and contents. |
| Parameters: |
blob - The Blob to decode. The image should be in PNG or
JPEG format.
|
| Return value: | A new Blob containing the specified subset. |
Blob encode([mimeType, options]) |
|
|---|---|
| Summary: | Saves the Canvas' contents to a binary format, such as PNG or JPEG. |
| Parameters: |
mimeType - Optional. The image format to encode to. Valid
values include "image/png" and "image/jpeg". The
default encoding is PNG.
options - Optional. A JavaScript object (i.e. key-value map)
that specifies encoding options. For lossy formats, such as JPEG, one
can specify a "quality" key, whose value should be a number
between 0.0 and 1.0 inclusive.
|
| Return value: | A new Blob encoding the Canvas' image data. |
void resize(w, h, [filter]) |
|
|---|---|
| Summary: | Resizes the Canvas. The resize happens "in-place", as opposed to returning a new Canvas. |
| Parameters: |
w - The new width.
h - The new height.
filter - Optional. A string specifying the image filter.
There are two options: "nearest" for nearest-neighbor
filtering, and "bilinear" for bi-linear filtering. The
default filter, if unspecified, is "bilinear".
|