GraphicImage Template
write()
Write an image out to the client browser
Syntax
GraphicImage = rb.GraphicImage.write(format, quality)
Parameters
The 'write' method takes 2 parameters:
Name | Type/Value | Range/Length | Description | format | string | | Required.
Type of the image to write (mime-type)
| quality | number | | Optional. An optional 'quality' for the resulting image. This currently is only used if the type is
specified as 'image/jpeg' and is used to specify the level of compression (and hence file size)
of the resulting image. For JPEG images, ommit this parameter to use the default quality (usually fine). Otherwise specify
a postive interger between 0 (lowest quality) to 95 (highest quality).
|
Results
The 'write' method returns GraphicImage:
Type/Value | Range/Length | Description |
GraphicImage |
  |
Returns a reference to 'this' if the operation succeeds, otherwise throws an exception.
|
Remarks This method tells Whitebeam to send the content of the image object to the client
browser in the format specified. This method is the most efficient way to send the image to the browser and avoids
unnecessary copying of data. Note : for application that need to generate the same image frequently it's worth
considering saving the resulting image, either in the file system or to the file template,
rather than regenerate each time. The mime-type should be one of the following external formats : - image/jpeg
A JPEG format image. - image/gif
A palette based 256 colour GIF image. - image/png
A PNG format image.
Example
// Load an image then create a smaller thumbnail to send to the browser
var src= new GraphicImage
src.make('/images/myBigImage.jpg','image/jpeg');
// Create a smaller thumbnail
var thumb = (new GraphicImage).create(100,100);
thumb.copyRect(srcImage,null,{z:0, y:0, w:100, h:100});
rb.page.setMimeType('image/jpeg');
thumb.write(thumb, 'image/jpeg');
|