Return to the tutorials
Return to the scripting


HDR Shop Scripting - The Image object

HDRShop 2.0 scripting is based on the Spidermonkey Javascript engine (external link) developed by Mozilla. This provides all the basic Javascript capabilities such as looping, conditional operators, variable, and functions. Just as a web browser provide specific functions for interacting with web pages, HDRShop provides custom functions and objects that allow for HDR image manipulation. Most of these functions are available through the Image class which represents an HDR image. In this tutorial we cover how to first create an image.
To create a new image, you use the standard contructor. You pass it the dimensions of the image. In this case the width is 640, the height is 480.
var img = new Image(640,480);
You can also gain control of an existing image using the GetImage function. You pass an image index where 0 corresponds to the first image opened.
var img = GetImage(index);
Similarly GetActiveImage returns a pointer to the current active image or undefined if no image is selected.
var img = GetActiveImage();
To load an image from a file.
var img = LoadImage(filename);
Or you can save an image.
image.Save(filename);
An image has three properties Width, Height, and Pathname. These provide the basic infomation about the image. If the image has no associated file on disk, then the Pathname will be undefined. So here is a script that demonstrates basic image handling.
img = new Image(640,480); // create a new image
img.Randomize(); // fills the image with random pixels
img.Save("foo.pfm"); // save the image
img.Close(0); // force the image to close
Sleep(1000); // wait a second
img = LoadImage("foo.pfm"); // load the image back in
// display image properties
Alert("Width = " + img.Width + "\nHeight = " + img.Height);





Return to the scripting
Return to the tutorials