Detailed reference of prototypes, properties and methods available in the
Javascript environment of your Helma web applications.

Default properties and methods of the Image prototype.
Image(img)
Helma's built-in image object allows you to read, manipulate, and save images.
An image object is created using the Image() constructor.
Example:

    var img = new Image("http://helma.org/image.gif");

parameters

String | img | as String of a URL, or a java.io.InputStream object

methods

- crop(x, y, width, height)

- dispose()

- drawLine(xStart, yStart, xEnd, yEnd)

- drawRect(x, y, width, height)

- fillRect(x, y, width, height)

- getHeight()

- getInfo(pathOfImage)

- getSource()

- getWidth()

- reduceColors(colorDepth, dither, alphaToBitmask)

- resize(width, height)

- resizeFast(width, height)

- setColor(red, green, blue)

- setFont(name, style, size)

- setTransparentPixel(index)

Methods
Image. crop(x, y, width, height)
Cuts out (crops) a rectanglular area of an image.
The dimensions of the area are calculated from the xNumber- and yNumber-offsets (ie. from the top left corner of the image as upper left reference point) to xNumber + widthNumber and yNumber + heightNumber as lower right reference point.
Example:

    var img = new Image("http://helma.org/images/original.gif");
    res.write('<:img src="/images/original.gif" />');

    img.crop(58, 9, 48, 21);
    img.saveAs("/www/images/processed.gif");
    res.write('<img src="/images/processed.gif" />');

parameters

Number | x | as Number, offset from the top left corner of the image
Number | y | as Number, offset from the lower right corner of image
Number | width | as Number, the width of the image
Number | height | as Number, the height of the image

Image. dispose()
Disposes an Image object that is no longer needed.
If an instance of java.awt.Graphics has been allocated for the Image, the dispose() method is called on it to free its resources.
Example:

    var img = new Image("http://helma.org/images/original.jpg");
    // do something useful or funny with the image
    img.dispose();

Image. drawLine(xStart, yStart, xEnd, yEnd)
Draws a line onto an image.
The line starts at the reference point defined by the offsets x1Number and y1Number from the top left corner of the image and ends at the reference point defined by the offsets x2Number and y2Number.
Example:

    var img = new Image("http://helma.org/images/original.gif");
    res.write('<img src="/images/original.gif" />');

    img.setColor(204, 0, 0);
    img.drawLine(58, 26, 100, 26);
    img.saveAs("/www/images/processed.gif");
    res.write('<img src="/images/processed.gif" />');

parameters

Number | xStart | as Number, horizontal reference point from top left corner of the image
Number | yStart | as Number, vertical reference point from top left corner of the image
Number | xEnd | as Number, horizontal reference point where the line ends in the image
Number | yEnd | as Number, vertical reference point where the line ends in the image

Image. drawRect(x, y, width, height)
Draws a rectangle onto an image.
The rectangle's dimensions are calculated from the xNumber- and yNumber-offset (ie. from the top left corner of the image as upper left reference point) to xNumber + widthNumber and yNumber + heightNumber as lower right reference point.
Example:

    var img = new Image("http://helma.org/images/originalgif");
    res.write('<img src="/images/original.gif" />');

    img.setColor(204, 0, 0);
    img.drawRect(57, 8, 46, 20);
    img.saveAs("/www/images/processed.gif");
    res.write('<img src="/images/processed.gif" />');

parameters

Number | x | as Number, as upper left reference point.
Number | y | as Number, as the lower right reference point upperleft
Number | width | as Number, width of the crop
Number | height | as Number, height of the crop

Image. prototye.drawString(textToDraw, x, y)
Draws text onto an image.
The string will be drawn starting at the xNumber- and yNumber-offset from the top left corner of the image.
Example:

    var img = new Image("http://helma.org/images/original.gif");
    res.write('<img src="/images/original.gif" />');

parameters

String | textToDraw | as String, the string to be drawn on the image.
Number | x | as Number, horizontal offset from the top left corner of the image.
Number | y | as Number, vertical offset from the top left corner of the image.

Image. fillRect(x, y, width, height)
Draws a filled rectangle onto an image.
The rectangle's dimensions are calculated from the xNumber- and yNumber-offset (ie. from the top left corner of the image as upper left reference point) to xNumber + widthNumber and yNumber + heightNumber as lower right reference point.
Example:

    var img = new Image("http://helma.org/images/original.gif");
    res.write('<img src="/images/original.gif" />');

    img.setColor(204, 0, 0);
    img.fillRect(58, 27, 43, 29);
    img.saveAs("/www/images/processed.gif");
    res.write('<img src="/images/processed.gif" />');

parameters

Number | x | as Number, from the top left corner of the image.
Number | y | as Number, from the lower reference point.
Number | width | as Number, width of the rectangle
Number | height | as Number, height of the rectangle

Image. getHeight()
Returns the height of an image measured in pixels.
Example:

    var img = new Image("http://helma.org/images/hop.gif");
    res.write('<img src="/images/hop.gif" />');

    var height = img.getHeight();
    res.write(height);
    35

returns

| Number

Image. getInfo(pathOfImage)
Returns an ImageInfo object for an image.
This function allows to retrieve image properties such as width, height and MIME type without the need to fully decode the image.
Example:

    var info = Image.getInfo("http://helma.org/images/hop.gif");
    if (info) {
      res.writeln('width: ' + info.width);
      res.writeln('height: ' + info.height);
    }

    width: 174
    height: 35

    Note that in contrast to the other Image function, this is called on the
    constructor rather than on a decoded Image object. This is because the
    purpose of this function is to avoid the expensive image decoding
    process if we're just interested in some of the image's properties.

    The function returns an instance of Marco Schmidt's ImageInfo object
    if the image could be read, or null if the image couldn't be read.
    See the ImageInfo API documentation for the full set of methods.
    (Remember that you can getters as properties in Rhino as shown in the example above.)

parameters

String | pathOfImage | as String, it can be a path, url, byteArray or inputstream.

returns

| ImageInfo

Image. getSource()
Retrieves a Java-compatible image object from a Helma image object.
To use some of the image filters provided by the JIMI Java image processing package com.sun.jimi.core.filters, a specific Java class of image objects is needed.
Helma wraps the sun.awt.image objects into a custom class. To use Helma image objects with JIMI's filters these have to be "unwrapped" using the getSource() function.
The following filter functions have been successfully applied the way as described in the examples below:

      * Rotate(degreeNumber)
      * Gray()
      * Flip(typeNumber)
      * Oil(intensityNumber)
      * Invert()
      * Smooth(intensityNumber)
      * Shear(degreeNumber)
      * Edges()
      * Shrink(multiplyNumber)
      * Enlarge(divisionNumber)

Please take into account that the quality might suffer depending on the type and amount of filters applied to the image.
Example:

    var img = new Image("http://helma.org/static/original.jpg");
    var filters = Packages.com.sun.jimi.core.filters;
    var rotator = new filters.Rotate(45);
    var processed = new Image(img, rotator);
    processed.saveAs("/path/to/static/processed.jpg");
    res.write('<img src="/static/processed.jpg" />');

    var oil = new filters.Oil(img.getSource(), 3);
    var processed = new Image(img, oil);
    processed.saveAs("/path/to/static/processed.jpg");
    res.write('<img src="/static/processed.jpg" />');

returns

| Packages.com.sun.awt.image

see

Packages.com.sun.awt.image

Image. getWidth()
Returns the width of an image measured in pixels.
Example:

    var img = new Image("http://helma.org/images/hop.gif");
    res.write('<img src="/images/hop.gif" />');

    var width = img.getWidth();
    res.write(width);
    174

returns

| Number

Image. reduceColors(colorDepth, dither, alphaToBitmask)
Reduces the number of available colors (color depth) in an image.
Note: GIF images need a color depth of 256 colors maximum. Use this function with caution, generally.
Example:

    var img = new Image("http://helma.org/images/original.jpg");
    res.write('<img src="/images/original.jpg" />');

    img.reduceColors(8);
    img.saveAs("/www/images/processed.jpg");
    res.write('<img src="/images/processed.jpg" />');

parameters

Number | colorDepth | as Number, value of color depth in an image.
Number | dither | as Boolean, optional parameter to enable dithering
Number | alphaToBitmask | as Boolean, optional parameter to use the alpha channel to create a bitmask

Image. resize(width, height)
Sets the height and width of an image to new values.
The widthNumber and heightNumber arguments need to be integers, so be careful to round the new values eventually.
In case of a GIF image always reduce the image to 256 colors after resizing by using the reduceColors() function.
Example:

    var img = new Image("http://helma.org/images/original.jpg");
    res.write('<img src="/images/original.jpg" />');

    var factor = 0.66;
    var wd = Math.round(img.getWidth() * factor);
    var ht = Math.round(img.getHeight() * factor);
    img.resize(wd, ht);
    img.saveAs("/www/images/processed.jpg");

    res.write('<img src="/images/processed.jpg" />');

parameters

Number | width | as Number, new width of the image.
Number | height | as Number, new height of the image.

see

Image.resizeFast

Image. resizeFast(width, height)
Resizes the image, using a fast and cheap algorithm.
parameters

Number | width | as Number, new width of the image.
Number | height | as Number, new height of the image.

see

Image.resize

Image. setColor(red, green, blue)
Sets the color for current drawing actions.
The colorNumber argument is represented by a 24-bit integer (0-16777215), the redNumber, greenNumber and blueNumber arguments build an RGB tuple with each element ranging from 0 to 255.
Example:

    var img = new Image("http://helma.org/images/original.jpg");
    res.write('<img src="/images/original.jpg" />');

    img.setColor(16777215);
    img.fillRect(80, 50, 30, 30);
    img.setColor(255, 255, 0);
    img.fillRect(65, 15, 30, 30);
    img.saveAs("/www/images/processed.jpg");
    res.write('<img src="/images/processed.jpg" />');

parameters

Number | red | as Number, RGB value ranging from 0 to 255 or if it the only parameter then it can be a 24 bit Integer
Number | green | as Number, RGB value ranging from 0 to 255
Number | blue | as Number, RGB value ranging from 0 to 255.

Image. setFont(name, style, size)
Determines the typeface font to be used in current drawing actions.
Using this function sets the font to be used in subsequent calls of the drawString() function.
The nameString argument specifies the font face as string (e.g. "sansserif", "dialog").
The integer styleNumber sets the font to normal (0), bold (1), italic (2) or bold and italic (3).
The sizeNumber, an integer as well, refers to the font size in pixels.
Please take a look at the description about adding fonts to the Java runtime for a detailed look onto Java's font mechanics.
Example:

    var img = new Image("http://helma.org/images/original.jpg");
    res.write('<img src="/images/original.jpg" />');

    img.setColor(255, 255, 255);
    img.setFont("serif", 0, 12);
    img.drawString("I shot the serif.", 50, 15);
    img.setFont("sansserif", 1, 14);
    img.drawString("But I didn't shoot", 10, 100);
    img.setFont("monospaced", 2, 16);
    img.drawString("the monotype.", 15, 115);
    img.saveAs("/www/images/processed.png");
    res.write('<img src="/images/processed.png" />');

parameters

String | name | as String, specifies the font face (e.g. "sansserif").
Number | style | as Number, the styleNumber normal (0), bold (1), italic (2) or bold and italic (3).
Number | size | as Number, refers to font size in pixels

Image. setTransparentPixel(index)
Sets the palette index of the transparent color for Images with an IndexColorModel. This can be used together with an Image's getPixel method.
parameters

Number | index | as Number, the index position specifying the transparent color.

see

Image.getPixel

Tue, 25 Nov 2008 16:50:10 GMT.

### core framework

- global
- app (application)
- req (request)
- res (response)
- session
- path
- root
- HopObject
- User
- File
- FtpClient
- Image
- Mail
- Remote
- Xml
- DatabaseObject
- MimePart
- Skin
- Object

### optional modules

- Array extensions
- Date extensions
- Number extensions
- Object extensions
- String extensions
- HopObject extensions
- global macros
- macro filters
- JSON methods
- helma.Aspects
- helma.Chart
- helma.Color
- helma.Database
- helma.File
- helma.Ftp
- helma.Group
- helma.Html
- helma.Http
- helma.Image
- helma.Mail
- helma.Search
- helma.Skin
- helma.Ssh
- helma.Url
- helma.Zip
- jala.BitTorrent
- jala.Captcha
- jala.Date
- jala.db
- jala.DnsClient
- jala.Form
- jala.History
- jala HopObject extensions
- jala.HtmlDocument
- jala.I18n
- jala.ImageFilter
- jala.IndexManager
- jala.ListRenderer
- jala.Mp3
- jala.PodcastWriter
- jala.RemoteContent
- jala.Rss20Writer
- jala.Utilities
- jala.XmlRpcRequest
- jala.XmlWriter

### java libraries

- browse docjar