Helpers

Image Utils

The image utils elements has some handy functions to manipulate and create images on the fly. It is located at CAAT.modules.ImageUtils and must be instantiated.

Alpha Sprite Sheet

The function createAlphaSpriteSheet(maxAlpha, minAlpha, sheetSize, image, bg_fill_style) creates a new image with an sprite sheet of transparent copies of the same image. The parameter bg_fill_style is optional, and if not set, it will create an image with transparency.

Example

Optimize

This function optimizes an image, that means, removes alpha transparency surrounding the image. the function is optimize(image, threshold). The threshold parameter indicates the minimum alpha value to consider transparent. It is useful to remove all that insets your graphician loves to leave around every bitmap he draws.

This is the original image, and the image optimized with a threshold of 32. Note the resulting image is smaller in size.

Thumb

The function createThumb(image, width, height, best_fit) creates a thumg from the original image of the given size. The source image will be scaled accordingly to fit the new size.

The parameter best_fit will try to fit the image as best as possible to keep its aspect ratio, otherwise, it will create a thumbnail of the given size.

In the example, the first thumb image, has a size which keeps aspect ratio. The second one, is drawn with best_fit to false and the third one with best_fit set to true.