OpenWGA 5.4 - TMLScript reference



Description The ImageScaler is a tool object to scale and convert image files from TMLScript. It is using the Java Advanced Imaging API plus some custom filters, offering an easy to use interface for these tasks.

An ImageScaler is created via method WGA.createImageScaler() taking an image file as parameter. The data of the image is loaded to the scaler ready to be scaled by the available methods. The modified image then again can be put out as regular file via scaler.writeImage() or attached to a document using this.attachScaledImage().

The capabilities of the ImageScaler object, especially which formats it can read and write, is dependent on the capabilities of the Java Advanced Imaging API. However on most platforms the valid input formats are JPEG, PNG, TIFF, GIF, and BMP (Windows Bitmap). Usable output formats are JPEG (the default) and PNG. See further information about this API on the  homepage of the Java Advanced Imaging API  or the Java Advanced Imaging API Programming Guide.

Because of licensing issues no ImageScaler implementation is available on OpenWGA server out of the box. You need to install an ImageScaler plugin, which is available as addon, to be able to use the functionality.

Retrieval WGA.createImageScaler()
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Properties and methods
Name Purpose
scaler.aspectRatio Returns the aspect ratio of the image
scaler.determineRenderedSize() Calculates the expected file size of the image in bytes
scaler.format Directly sets the target format for storage
scaler.formatSuffix Returns the file suffix of the chosen output format
scaler.growToSize(width, height) Enlargens the image to minimal sizes for both dimensions
scaler.height Returns the current height of the image in pixels
scaler.imageEncodeParam Sets encoding parameters for that target format of the file
scaler.interpolation Controls the interpolation strategy used for scaling
scaler.isTransparencySupportedForOutput() Returns if the chosen output format supports transparency
scaler.quality Controls the "quality" of the output format
scaler.scaleByFactor(widthFactor, heightFactor) Scales the image based on a factor
scaler.scaleToSize(width, height [, keepRatio]) Scales the image to an absolute target size
scaler.shrinkToSize(width, height) Shrinks the image to a maximum size for both dimensions
scaler.sourceFileName Returns the name of the source file
scaler.useJPEGForOutput() Configured the scaler to use JPEG as output format
scaler.usePNGForOutput() Configures the scaler to use PNG as output format
scaler.width Returns the current width of the image in pixels
Writes the image data to some output
Examples The following example processes an image file that is uploaded from a WebTML form. The image is scaled so that it does not exceed a maximum size of 800x600 pixels, while keeping the ratio.The actual result size therefor will be lower than the given values on one dimension.

First ther form to upload the file:

<tml:form id="uploadImage">
Image: <tml:input name="thefile" type="file"/><br/>
<tml:button clickaction="scale">Scale image</tml:button>

Then the code of the action: The method tmlform.getFile() is used to get a regular file object for the uploaded file, which is neccessary to pass it on to the scaler. In this example the method this.attachScaledImage() is used to directly attach the modified data in the Scaler to the current context document. Note the omitted suffix on the output file name.

<tml:action id="scale">
  var scaler = WGA.createImageScaler(tmlform.getfile(tmlform.thefile));
  scaler.shrinkToSize(800, 600);
  attachScaledImage(content(), scaler, "scaled");