Whitebeam Object Definition

Site Map
 
Home
 
Application Guide
Reference
  Installation
  Configuration
  XML Markup
  JavaScript Classes
  ROM
  Templates
  Environment
  Dev Process
  Tools
  External Links
  Example libraries
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

Whitebeam Object Definition

Method Description

GraphicImage.toBinary()

Write an image out to an instance of a the Binary class.

Syntax

GraphicImage = GraphicImage.toBinary(targetObject, format, quality)

Parameters

The 'GraphicImage.toBinary' method takes 3 parameters:

Name Type/Value Range/Length Description
targetObjectstruct GraphicImage.Binarysee definition Required. Target Binary object to which to write the formatted image
formatstring  Required. Type of the image to write (mime-type)
qualitynumber  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 'GraphicImage.toBinary' 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 performs exactly the same transformation as GraphicImage.write, and then writes the result to the binary object rather than to the client browser.

Use this method when you want to do subsequent processing of an image, or where the image is to be saved in the database or to the file system.

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

  // Copy the whole of the rectangle into a target size of 100x100.
  thumb.copyRect(srcImage,null,{z:0, y:0, w:100, h:100});

  // Save the resulting thumbnail into a Binary object and then to 
  // the file system.
  var thumbBinary = new Binary;
  var thumbFile = new Binary;

  thumb.toBinary(thumbBinary,'image/jpeg');
  thumbFile.open('/mythumb.jpg','wb');
  thumbFile.write(thumbBinary);
  thumbFile.close();
        
Whitebeam release 1.3.36
(loadtime : 22ms)