A SERVICE OF

logo

12
Chapter 2
The Media Object
The most important built-in object in MediaScript is the Media object, which implements
the many image processing features provided by MediaRich. A typical script creates one
or more Media objects by either loading image data from a file or using the Media drawing
methods. The script then performs additional image processing operations based on
arguments and parameters in the request. Finally, the script generates a response by saving
a Media object to the desired output file format.
For example, a script to scale an image might look like the following:
function main(imageName, width, height)
{
var img = new Media();
img.load(name @ imageName);
img.scale(xs @ width, ys @ height, alg @ "best");
img.save(type @ "jpeg");
}
For a complete description of all of the methods provided by the Media object, see
Chapter 3, “MediaScript Objects and Methods.”
Preprocessor Directives
Preprocessor directives are lines included in the code of our programs that are not program
statements but directives for the preprocessor. These lines are always preceded by a pound
sign (#) and are processed before the rest of the script and direct the way the script
commands are interpreted.
These preprocessor directives extend only across a single line of code. As soon as a newline
character is found, the preprocessor directive is considered to end. No semicolon (;) is
expected at the end of a preprocessor directive. The only way a preprocessor directive can
extend through more than one line is by preceding the newline character at the end of the
line by a backslash (\).
The following statements are collectively called preprocessor directives, since they are
processed before the rest of the script and direct the way the MediaScript commands are
interpreted.
Using the #include Directive
The #include directive is a preprocessing flag that is evaluated before the script is parsed
or executed. It allows other scripts to be included as if they were part of the original script
and takes a string representing the relative path of the script filename to include. The string
must be enclosed in double quotes.
Syntax
#include <"relative path to the included file">;