Ti.ImageFactory Module
Description
This module provides a set of image transformation functions.
Accessing the Ti.ImageFactory Module
To access this module from JavaScript, you would do the following:
var ImageFactory = require('ti.imagefactory');
Functions
imageWithAlpha
Creates a new image by creating a copy of the given image, adding an alpha channel if it doesn't already have one.
Arguments
- Image blob[blob]: Image to transform
- Options[dictionary]: A dictionary specifying the options for the transformation
- Currently there are no properties for this method -- specify an empty dictionary
imageWithTransparentBorder
Creates a new image by creating a copy of the given image, adding a transparent border of the given size around its edges. The size of the image will be expanded by the specified border size.
Arguments
- Image blob[blob]: Image to transform
- Options[dictionary]: A dictionary specifying the options for the transformation
- borderSize[int]: The size of the border (default: 1)
imageWithRoundedCorner
Creates a new image by creating a copy of the given image with rounded corners.
Arguments
- Image blob[blob]: Image to transform
- Options[dictionary]: A dictionary specifying the options for the transformation
- borderSize[int]: The size of the border (default: 1)
- cornerRadius[int]: The radius of the corner edges (default: 0)
imageAsThumbnail
Creates a new image by creating a copy of the given image that is squared to the thumbnail size.
Arguments
- Image blob[blob]: Image to transform
- Options[dictionary]: A dictionary specifying the options for the transformation
- size[int]: The size of the thumbnail (default: 48)
- borderSize[int]: The size of the border (default: 1)
- cornerRadius[int]: The radius of the corner edges (default: 0)
- dither[boolean]: Indicates if dithering should be applied while scaling. May provide better quality (default: true)
imageAsResized
Creates a new image by creating a copy of the given image that is rescaled to the specified size.
Arguments
- Image blob[blob]: Image to transform
- Options[dictionary]: A dictionary specifying the options for the transformation
- width[int]: The width of the new image (default: image width)
- height[int]: The height of the new image (default: image height)
imageAsCropped
Creates a new image by creating a copy of the given image that is cropped to the specified bounds.
Arguments
- Image blob[blob]: Image to transform
- Options[dictionary]: A dictionary specifying the options for the transformation
- width[int]: The width of the new image (default: image width)
- height[int]: The height of the new image (default: image height)
- x[int]: The x-coordinate of the upper-left corner of the bounds (default: image center - width / 2)
- y[int]: The y-coordinate of the upper-left corner of the bounds (default: image center - height / 2)
imageTransform
Creates a new image by applying a sequence of transformations to the image.
Arguments
- Image blob[blob]: Image to transform
- Transform[dictionary]: A sequence of transform specifications. Transforms are listed as additional parameters to the function and are applied in the order specified. Each transform is a dictionary with the options described above for each transform along with an additional 'type' property included with each dictionary of transform options.
- type[int]: The identifier of the transform to apply. One of the following constants
- imagefactory.TRANSFORM_CROP
- imagefactory.TRANSFORM_RESIZE
- imagefactory.TRANSFORM_THUMBNAIL
- imagefactory.TRANSFORM_ROUNDEDCORNER
- imagefactory.TRANSFORM_TRANSPARENTBORDER
- imagefactory.TRANSFORM_ALPHA
- options as described in the above transforms
compress
Creates a new image by creating a copy of the given image and applying the specified compression quality.
Arguments
- Image blob[blob]: Image to compress
- Compression Quality[float]: The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 1.0)
compressToFile(image, compression, fileURL)
Compresses the provided image straight out to a file. This method is quite a bit lighter on memory usage than the others.
Arguments
- Image blob[blob]: Image to compress
- Compression Quality[float]: The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 1.0)
- File URL[string]: The path to the file where we will save the newly compressed image.
Usage
See example.
Author
Jeff English
Module History
View the change log for this module.
Feedback and Support
Please direct all questions, feedback, and concerns to info@appcelerator.com.
License
Copyright(c) 2010-2011 by Appcelerator, Inc. All Rights Reserved. Please see the LICENSE file included in the distribution for further details.