## Image

    Object
       |
       +--Image

Defined in Image.js

SUMMARY: Constructor | Properties | Methods | DETAIL: Constructor | Properties | Methods

Constructor Summary
`Image(<String> url)` Helma's built-in image object allows you to read, manipulate, and save images.

Methods Summary
`void` | `crop(<Number> x, <Number> y, <Number> width, <Number> height)` Cuts out (crops) a rectanglular area of an image.
`void` | `dispose()` Disposes an Image object that is no longer needed.
`void` | `drawLine(<Number> xStart, <Number> yStart, <Number> xEnd, <Number> yEnd)` Draws a line onto an image.
`void` | `drawRect(<Number> x, <Number> y, <Number> width, <Number> height)` Draws a rectangle onto an image.
`void` | `fillRect(<Number> x, <Number> y, <Number> width, <Number> height)` Draws a filled rectangle onto an image.
`Number` | `getHeight()` Returns the height of an image measured in pixels.
`ImageInfo` | `getInfo(<String> pathOfImage)` Returns an ImageInfo object for an image.
`awt.image` | `getSource()` Retrieves a Java-compatible image object from a Helma image object.
`Number` | `getWidth()` Returns the width of an image measured in pixels.
`void` | `reduceColors(<Number> colorDepth)` Reduces the number of available colors (color depth) in an image.
`void` | `resize(<Integer> width, heigth)` Sets the height and width of an image to new values.
`void` | `setColor(<Number> red, <Number> green, <Number> blue)` Sets the color for current drawing actions.
`void` | `setFont(<String> name, <Number> style, <Number> size)` Determines the typeface font to be used in current drawing actions.

Constructor Detail

### Image

    Image(<String> url)

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:

`url` - as String

Method Detail

### crop

    void crop(<Number> x, <Number> y, <Number> width, <Number> 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:

`x` - as Number, offset from the top left corner of the image

`y` - as Number, offset from the lower right corner of image

`width` - as Number, the width of the image

`height` - as Number, the height of the image

### dispose

    void 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();

### drawLine

    void drawLine(<Number> xStart, <Number> yStart, <Number> xEnd, <Number> 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:

`xStart` - as Number, horizontal reference point from top left corner of the image

`yStart` - as Number, vertical reference point from top left corner of the image

`xEnd` - as Number, horizontal reference point where the line ends in the image

`yEnd` - as Number, vertical reference point where the line ends in the image

### drawRect

    void drawRect(<Number> x, <Number> y, <Number> width, <Number> 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:

`x` - as Number, as upper left reference point.

`y` - as Number, as the lower right reference point upperleft

`width` - as Number, width of the crop

`height` - as Number, height of the crop

### fillRect

    void fillRect(<Number> x, <Number> y, <Number> width, <Number> 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:

`x` - as Number, from the top left corner of the image.

`y` - as Number, from the lower reference point.

`width` - as Number, width of the rectangle

`height` - as Number, height of the rectangle

### getHeight

    Number 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

### getInfo

    ImageInfo getInfo(<String> 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:

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

Returns:

ImageInfo

### getSource

    awt.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

### getWidth

    Number 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

### reduceColors

    void reduceColors(<Number> colorDepth)

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:

`colorDepth` - as Number, value of color depth in an image.

### resize

    void resize(<Integer> width, heigth)

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:

`width` - as Number, new width of the image.

`height` - as Number, new height of the image.

### setColor

    void setColor(<Number> red, <Number> green, <Number> 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:

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

`green` - as Number, RGB value ranging from 0 to 255

`blue` - as Number, RGB value ranging from 0 to 255.

### setFont

    void setFont(<String> name, <Number> style, <Number> 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:

`name` - as String, specifies the font face (e.g. "sansserif").

`style` - as Number, the styleNumber normal (0), bold (1), italic (2) or bold and italic (3).

`size` - as Number, refers to font size in pixels

SUMMARY: Constructor | Properties | Methods | DETAIL: Constructor | Properties | Methods

Documentation generated by JSDoc on Thu Apr 5 01:59:00 2007