2013-07-10: The module is not in active development – but as far as I have heard, it works with version 3.3.1 and older of the SDK. Make sure to configure it before building (see below).
Imaging module for Titanium on iOS
This module adds native image manipulation methods and control of JPEG compression to Titanium.
It provides a subclass of TiBlob, ComSpiirImage, enriched with new methods and properties.
var blob = Ti.Filesystem.getFile('file.jpg').read(); var image = imaging.createImageFromBlob(blob);
As images are blobs, they can be used anywhere where Titanium expectes blobs.
Below are simple examples of use — check out example/app.js for more code.
To get the module to build, you most likely need to adjust
TITANIUM_SDK_VERSION and possibly also
titanium.xcconfig, to reflect the SDK you are building against.
By default, Titanium compresses JPEG images using 100% quality, which results in huge files. The Imaging module addresses this:
var blob = Ti.Filesystem.getFile('large.jpg').read(); var image = imaging.createImageFromBlob(blob); image.compressionQuality = 0.1; Titanium.Filesystem.getFile('small.jpg').write(image);
Scaling an image down
The method scaleImage scales an image down, retaining proportions:
var image = imaging.createImageFromBlob(blob); var scaledImage = image.scaleImageDown(600, 400);