MediaRich for SharePoint 2003 Programmer’s Guide
© 2003-2006 Automated Media Processing Solutions, Inc. dba Equilibrium. All Rights Reserved. U.S. Pat. No. 6,792,575 for automated media processing and delivery. Other patents pending. Equilibrium, MediaRich, the MediaRich and Equilibrium logos, and MediaScript are trademarks of Equilibrium. Adobe and Photoshop are registered trademarks of Adobe Systems Inc. All other products or name brands are the trademarks of their respective holders.
Table of Contents •••••• Chapter 1 Programming MediaRich for SharePoint 5 MediaRich for SharePoint 2003 Features 6 The Application Programming Framework 7 Working with MediaScript 7 Using the processImage Function 8 Deploying a New MediaScript 9 Metadata Support 9 Chapter 2 Using MediaScript 11 The Media Object 12 Preprocessor Directives 12 Using the #include Directive 12 Using the #link Directive 13 Named Arguments 13 File Systems 14 File System Specifiers 14 Creating Custom File System Aliases 15 File
Text Response Object 153 TextResponse Object Methods 153 ICC Profile Object 155 static function list(colorspace, class) 155 ICC Profile Object Methods 156 IccProfile.
Chapter 1 Programming MediaRich for SharePoint •••••• MediaRich for SharePoint is a client-server system that allows users to perform image processing tasks using media stored in Microsoft SharePoint Portal Server. It includes an “out-of-the-box” interface where users perform these tasks using either the Export interface, which is available from MediaRich Document Libraries, or the MediaRich MediaCart site, which is available from the MediaRich Browser.
MediaRich for SharePoint 2003 Features File Format Support MediaRich for SharePoint extends SharePoint’s standard picture library to provide previews of CMYK images, Vector images, and layered Photoshop® files along with related metadata. It reads and writes many popular file formats including BMP, WBMP, GIF, JPG, PNG, PCT, TIFF, PDF, TGA, Adobe Illustrator®, and Photoshop PSD or EPS files.
The Application Programming Framework MediaRich image processing is controlled by MediaScript, which provides a simple framework that makes writing new scripts easy.
Using the processImage Function The MediaScript API for SharePoint is comprised of a single function your script must define. This enables the script to function correctly both as an Export script and a MediaCart script. In the case of the MediaCart, the same script is used for each image in a MediaCart batch. Syntax Media processImage(Media image) The processImage function is the single entry point for all scripts that interoperate with the MediaRich for SharePoint Connector.
Setting the save parameter “type” determines what type of image the framework is going to save. The save parameters correspond to the parameters that can be passed to the Media object’s save() method. For some formats, such as GIF and JPEG, there are many more parameters that can be specified. NOTE: For more information about what parameters are available for saving images, see “save()” on page 124. Before returning control to the framework, you must complete a final step: resp.
• • • • • 10 Chapter 1
Chapter 2 Using MediaScript •••••• All MediaRich image templates are written in MediaScript, an interpreted scripting language based on the ECMAScript Language Specification, 3rd edition (which, in turn, is based on Netscape's JavaScript and Microsoft's JScript). By building on top of a widely known scripting language, MediaScript can offer all of the flexibility of a full programming language while remaining easy to use.
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.
Example #include "process/library.ms"; If your MediaScript uses the XMLdocument object, you need to use the #include directive to specify the xml.ms that installs with MediaRich. Do this by adding the following line at the beginning of your script: #include "sys:xml.ms"; Using the #link Directive The #link directive is a preprocessing flag that is evaluated before the script is parsed or executed.
All of the functions that use named arguments also accept a single object as an argument. If an object is passed, each of the object's properties corresponds to an argument name/value pair; the property's name is the argument name and the property's value is the argument value. For example, the previous MediaScript could be rewritten as the following: var argsObject; argsObject.name = "out.jpg"; argsObject.quality = 90; img.
File System Specifier Default Location profiles \MediaRich\Shared\Originals\Profiles read \MediaRich\Shared\Originals\Media results \MediaRich\Shared\Generated\MediaResults scripts \MediaRich\Shared\Originals\Scripts sys \MediaRich\Shared\Originals\Sys write \MediaRich\Shared\Originals\Media All MediaScript operations that take a path default to a reasonable file system when no specifier is present in the path.
“\\STOR1\source” and write the output to a web server with a UNC path of “\\WEB1\retail1\images”, append the entries to your local.properties file, as in the following example: virtualfilesystem.retailIN=\\\\STOR1\\source virtualfilesystem.retailOUT=\\\\WEB1\\retail1\\images NOTE The backslash character (\) is the escape character for MediaRich properties files. All backslashes in the path must be escaped with an additional backslash.
HTTP Support Using the FSNet Plug-in The FSNet plug-in can implement HTTP and FTP access via standard URLs by defining virtual filesystems named “http” and “ftp”. FSNet and MediaRich Virtual Filesystems MediaRich accesses files by defining a number of virtual filesystems. A virtual file system indicates the root of a file tree located somewhere on either the local filesystem or on the network.
A fully specified HTTP or FTP URL looks like the following: (http|ftp)://:@:/ The , , and portions of the URL are optional. Here are some examples of well formed URLs: http://www.eq.com/images/eq_bw.gif http://joeblow:abcdefg@acomputer/myimages/blah.jpg ftp://ftpserver:1234/public/images/camera.tif FSNet Properties A number of properties can be set in the local.
File Caching The process of reading a file over a network can be time consuming. For this reason, files read via the FTP and HTTP protocols are stored in a local file cache. Subsequent accesses to the same file that occur shortly after the file was last downloaded are served from the cache rather than reread from the network. The RefreshInterval property determines how HTTP and FTP files are cached.
Defining Additional FSNet Virtual Filesystems Any number of virtual filesystems can be defined in addition to standard “http” and “ftp” filesystems. The only reason to define additional HTTP or FTP filesystems would be to associate different property settings with the different filesystems. For example, if you needed to access network files via two different proxy servers, you would need two different filesystems, as the proxy server can not be specified in a virtual file path (in a URL).
The following table lists the properties you can configure for either FTP or HTTP: Property Usage Disabled Set to 1 to disable the file system, 0 or no entry to enable it Specifier This is the path specifier that denotes this file system. UserName Sets the default user name. Password Sets the default password. UserNameAndPassword Sets the default username and password (separated by “:”). FTP Set to 1 to use FTP protocol, 0 or no entry to use HTTP.
• • • • • 22 Chapter 2
Chapter 3 MediaScript Objects and Methods •••••• MediaScript includes a number of built-in objects that you can use to customize your MediaRich requests and responses.
Error Handling Most MediaScript functions indicate an error condition by throwing an exception rather than returning an error code. Exceptions can be trapped and handled using ECMAScript's standard try/catch/finally mechanism. For example, the Media object's load() method throws an exception if the file to be loaded is not found. To trap this exception, you would write something like the following: try { img.load(name @ "missingFile.tga"); } catch (e) { // Here you can recover from the error.
• • • • • • • • • length() list() mkdir() read() readNextLine() remove() rename() rmdir() write() new File() The File object needs to be constructed using the new File () constructor. Syntax var Test = new File( <"filename"> ); Parameters filename - specifies a string containing the filename and path with which the object is associated. The default is an empty string. The string must be in quotes. If the string does not specify a file system the default is the write file system.
copy() Copies the File object to a new filename. The object’s original filename is unchanged. Syntax
Parameters This function takes no parameters. getLastModified() Returns the last modified date in seconds since midnight January 1, 1970. If the file does not exist or cannot be accessed, the function returns 0. Syntax
isDirectory() Returns true if the File object points to a directory, otherwise returns false. Syntax .isDirectory(); Parameters This function takes no parameters. isFile() Returns true if the File object points to a regular file, otherwise returns false. Syntax .isFile(); Parameters This function takes no parameters. length() Returns an integer containing the number of text lines in the file. Syntax .length(); Parameters This function takes no parameters.
read() Reads the specified line number from the file and returns it as a string. NOTE: Line numbers start at zero, not at one. Syntax .read( ); Parameters index - specifies the line number and can range from 0 to 16,777,215. readNextLine() Reads the next line from the file pointed at by the File object, and returns a string containing the text in that line. Returns undefined at the end of the file. Syntax .readNextLine(); Parameters This function takes no parameters.
rmdir() Removes the specified directory and returns true if the directory could be removed and false if it could not. Syntax var success = .rmdir( <"recurse"> ); Parameters recurse - controls whether the contents of the specified directory are deleted. If this is set to true, the directory and all of its content is removed. If set to false, the directory is only deleted if it is empty. write() Writes a string to the end of the file. Syntax .
The response object can be any of the following types: Media, XmlDocument, or TextResponse. For more information about the setObject() method, see “setObject()” on page 37. Finally, the response contents can be set directly to the path of an existing file using the response object's setPath() method. For example, to return a PDF file in the media directory named response.pdf, you would write: resp.setPath("response.pdf"); By default the file will be copied to the cache.
• • • • getJobId() getBatchId() getJobTempDir() getBatchTempDir() getParameter() Returns the MRL parameter specified by name, or null if no such parameter exists. Syntax var paramValue = req.getParameter( ); Parameters name - specifies the name of the MRL parameter to retrieve. getParameterNames() Returns an array of the names of all parameters specified on the MRL. Syntax var nameArray = req.getParameterNames(); Parameters This function takes no parameters.
Example function main() { var respText = new TextResponse(TextResponse.TypePlain); var headers = req.getHeaderNames(); for (var i = 0; i < headers.length; ++i) { respText.append(headers[i] + ": " + req.getHeader(headers[i]) + "\n"); } resp.setObject(respText, RespType.Streamed); } Sample Output accept: */* accept-encoding: gzip, deflate accept-language: en-us connection: Keep-Alive host: localhost user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.
Example Suppose that a file parameter is passed to a script with a parameter name of “testFile”. This file can be accessed within a script as follows: var path = req.getFileParamPath("testFile"); var m = new Media(); m.load(name @ path); getHeaderNames() Returns an array of all HTTP header names for the current request. Syntax req.getHeaderNames(); Parameters This function has no parameters. Example function main() { var respText = new TextResponse(TextResponse.TypePlain); var headers = req.
getQueryString() Returns the query string portion of the MRL that originated the request (everything after the “?”). Syntax var queryString = req.getQueryString(); Parameters This function has no parameters. getScriptPath() Returns a string containing just the query component of the URL used to generate the executing request. Syntax req.getScriptPath(); Parameters This function has no parameters. Example If the original URL is, http://MRserver/mgen/fotophix/photochange.ms?args=%22pic3.
Parameters This function has no parameters. getJobTempDir() Returns the path to a local temporary directory for use by the current job. This directory is created at the start of each request and deleted when the request completes. Syntax var tmpDir = req.getJobTempDir(); Parameters This function has no parameters. getBatchTempDir() Returns the path to a local temporary directory that is shared by all jobs within a given batch.
• • • • • • • • • getSaveParameters() setMimeType() getMimeType() setHeader() getHeader() setStatusCode() getStatusCode() write() writeLine() setObject() Sets the response object. Optional parameters can set the response type and save parameters for the specified object. Syntax resp.setObject( [obj] [respType] [saveParams{}] ); Parameters obj - specifies the response object. RespType - optional parameter that sets the response type: • RespType.
Syntax resp.getObject(); Parameters This function has no parameters. setPath() Sets the response file path. An optional parameter can set the response type. Syntax resp.setPath(filePath, RespType); Parameters filePath - sets the response file path. If the path does not specify a file system the default is the read file system. See “File Systems” on page 14 for more information. RespType - optional parameter that sets the response type: • RespType.
Syntax resp.setMedia( ); getMedia() Returns the current response Media object. Syntax resp.getMedia(); Parameters This function has no parameters. setResponseType() Sets the response type. Syntax resp.setResponseType( [RespType] ); Parameters RespType - sets the response type: • RespType.Cached saves the response object or file to the MediaResults cache directory so that future requests are returned directly by the filter. • RespType.
setSaveParameters() Sets the response save parameters for the response media object. Syntax resp.setSaveParameters( ); Parameters save parameters - specified as either an object, or in the standard syntax (for example, type @ “jpeg”). These parameters are passed directly to the Media object save method. For a description of these parameters, see “save()” on page 124. getSaveParameters() Returns the current save parameters for the response Media object. Syntax resp.
Parameters name - the string name indicating the HTTP header value - the string value of the HTTP header. getHeader() Returns the value for the given HTTP header name. Syntax req.getHeader( ); Parameters The only parameter is the specified header name. Example function main() { var respText = new TextResponse(TextResponse.TypePlain); var headers = req.getHeaderNames(); for (var i = 0; i < headers.length; ++i) { respText.append(headers[i] + ": " + req.getHeader(headers[i]) + "\n"); } resp.
getStatusCode() Returns the response status code. Syntax var code = resp.getStatusCode(); Parameters This function has no parameters. write() Appends the specified text to the response object. When you use this method, you should set the mime type to the type of text written (such as text/plain, text/xml, etc.). Syntax resp.write("This is the response"); resp.setMimeType("text/plain"); Parameters The only parameter is the specified text string.
Media Object The Media object 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. Class Methods There are static methods on the Media object.
Example var fileInfo = Media.getFileInfo(name @ "tif/32bit.tif"); for (key in fileInfo) { print(key + ":" + fileInfo[key] + "\n"); } Individual properties can be accessed like this: var fileInfo = Media.getFileInfo(name @ "tif/32bit.tif"); var width = fileInfo["Width"]; getFileFormats() Use this method to get a description of the available file formats. It returns an array of objects describing the available file formats. Each element of the array contains the following fields: • type: The file format type.
Example This example returns a text file describing all of the available file formats. #include "sys:/TextResponse.ms" function main() { var foo = Media.getFileFormats(); var txt = new TextResponse(); for (var i = 0; i < foo.length; ++i) { txt.append(foo[i].type + ":\n"); txt.append(" exts: " + foo[i].extensions + "\n"); txt.append(" flags: "); if (foo[i].flags & Media.FormatLoad) txt.append("load "); if (foo[i].flags & Media.FormatSave) txt.append("save "); if (foo[i].flags & Media.FormatCmykSave) txt.
Parameters extension - the file system extension whose type is desired (such as “psd”).
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • getImageFormat() getInfo() getLayer() getLayerBlend() getLayerCount() getLayerEnabled() getLayerHandleX() getLayerHandleY() getLayerIndex() getLayerName() getLayerOpacity() getLayerX() getLayerY() getMetaData() getPalette() getPaletteSize() getPixel() getPixelFormat() getPixelTransparency() getPopularColor() getResVertical() getResHorizontal() getSamplesPerPixel() getWidth() getXmlInfo() glow() importChannel() infoText() line()
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • polygon() quadWarp() reduce() rectangle() rotate() rotate3d() save() saveEmbeddedProfile() scale() selection() setColor() setFrame() setLayer() setLayerBlend() setLayerEnabled() setLayerHandleX() setLayerHandleY() setLayerOpacity() setLayerPixels() setLayerX() setLayerY() setMetadata() setPixel() setResolution() setSourceProfile() sharpenSharpen() sharpenSharpenMore() sharpenUnsharpMask() sizeText() stylizeDiffuse() stylizeEmboss() stylize
adjustHsb() Alters the HSB levels of an image. It can be applied to images of all supported bit-depths. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see selection(). Syntax adjustHsb( [Hue @ ] [Saturation @ ] [Brightness @ ] [UseHLS @ ] ); Parameters The default value for any parameter not specified is zero.
adjustRgb() Alters the contrast, brightness, and color balance of an image. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see selection().
arc() Draws and positions an arc on the image based on the specified parameters. This method accepts all composite() parameters except HandleX and HandleY. The foreground color may vary with this function, depending on the original Media object. If the object has a set foreground color, or it is set with the setColor() function, MediaRich uses the set color.
Ry - specifies (in pixels) the radius of the ellipse (from which the arc is derived) on the y axis. This parameter is required and has no default value. Startangle - indicates the point of the ellipse (from which the arc is derived) where the arc begins. This parameter is required. There is no default value. Endangle - indicates the point of the ellipse (from which the arc is derived) where the arc ends. This parameter is required. There is no default value. Opacity - specifies opacity of the drawn object.
Example var image = new Media(); image.load(name @ "logobg.tga"); image.arc(X @ 185, Y @ 121, Rx @ 175, Ry @ 111, StartAngle @ -120, EndAngle @ 60, Width @ 2, Smooth @ true, WarpAngles @ true); image.save(type @ "jpeg"); blur() Applies a simple blur filter on the image. For each pixel, all the pixels within the given radius are averaged and the result put in the destination image. This function fully supports CMYK.
Example var image = new Media(); image.load(name @ "peppers.tga"); image.blur(radius @ 12); image.save(type @ "jpeg"); blurBlur() Applies a similar but milder blur effect as the blur() function. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax blurBlur(); Parameters There are no parameters for this function.
blurGaussianBlur() Applies a Gaussian blur effect to the image. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax blurGaussianBlur( [Radius @ ] ); Parameters Radius - specifies the extent of the effect. The default is 1.00. Example var image = new Media(); image.load(name @ "peppers.tga"); image.
Example var image = new Media(); image.load(name @ "peppers.tga"); image.blurMoreBlur(); image.save(type @ "jpeg"); blurMotionBlur() Simulates the type of blur that results from motion (as in the photo of a tree photographed from a moving car). NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax blurMotionBlur( [Angle @
Example var image = new Media(); image.load(name @ "peppers.tga"); image.blurMotionBlur(Angle @ 30, Distance @ 10); image.save(type @ "jpeg"); clone() Copies one Media object into another. After a Media object has been cloned, both the original and the copy can be modified independently, with changes to one object not affecting the other. Syntax .clone(); Parameters This function has no parameters. Example var original = new Media(); original.load(name @ "weasel.tga"); original.
Parameters layers - specifies the layers to collapse and the order in which to collapse them. The layer numbers begin at 0 (background) and go up. The default collapses all layers from bottom to top. The layer list must be contained in quotes and consists of comma-separated entries. You can specify ranges (“0-2”) or individual layers (“0,2”). If you specify the layers out of order, and they are composited accordingly.
colorCorrect() Transforms an image from a source color space to a destination color space. MediaRich supports ICC profiles for the following formats: EPS, JPEG, PDF, PS, PSD, and TIFF. Specifying ICC profiles: The sourceProfile and destProfile parameters may be specified either as a filename or as an IccProfile object.
• “AbsoluteColorimetric” - corrects the image to the absolute white point specified in the destination ICC profile. • “Saturation” - works best for line art and images that have large areas of one solid color. NOTE: For multi-layer images, profiles are associated only with the image and not with any of the layers; thus using colorCorrect() affects all layers. For more information, please see Appendix B, “MediaRich Color Management.”. Example var image = new Media(); image.load(name @ "car.jpg"); image.
Example var image = new Media(); image.load(name @ "car.tga"); image.selection(name @ "mskcar.tga"); image.colorize(color @ 0x009900); image.save(type @ "jpeg"); colorFromImage() The specified color is converted to the colorspace defined by the destination profile from the colorspace defined by the source profile and returned to the caller. By default, the source profile is the profile embedded in the image. The specified rendering intent is used for the conversion.
This example converts the color (red) to the colorspace defined by the profile embedded in image. If image has no embedded profile, an exception is thrown. Assuming the image is a cmyk image with an embedded profile, the resulting color will be the rgb color corresponding to color. NOTE: If a Color Profile is associated with an RGB image, this is considered unnecessary data and by default the attached profiles will not be saved to RGB images.
composite() Composites the specified foreground (source) image onto the current (background) image. The image specified by source must be loaded separately. The background and source images can be any bit-depth. Transparency is available only for 16-bit, 32-bit, 40-bit (CMYK-A) images with the alpha channel of the source image being used to determine transparency levels. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection.
If Source or Name is not specified, MediaRich will perform a color-fill when you also specify the Color parameter. For example, if you composite without naming a source, and specify the color green (0x009900), the green will appear composited over the entire background or onto the area of the background as specified through a selection (as with the following example). var image = new Media() var image2 = new Media(); image.load(name @ "car.tga"); image2.load(name @ "mskcar.tga"); image.
IgnoreAlpha - when set to true, the source is composited onto the target and alpha channel information is ignored. The default is false. X and Y - specify the position of the source image, with the center as anchor point. For example, if “x @ 100, y @ 50" is specified, the center of the source image will be located at pixel (100,50) on the target image. If these parameters are not specified, the center of the source image is located at pixel (0,0).
convert() Converts the image to the specified type/bit-depth. The 8-bit type is not supported, since this involves a much more complex transformation (palette selection, etc.) — instead, use reduce(). When converting images with no alpha channel, the generated alpha channel is based on the background color of the original if the background is set to transparent. Otherwise, the resulting alpha channel is solid white.
layers - for PSD files, specifies the layers to be converted. Specify the layers to collapse and the order in which to collapse them. The layer numbers begin at 0 (background) and go up. For more information see “load()” on page 101. Example var image = new Media(); image.load(name @ "peppers.tga"); image.convert(rtype @ "Grayscale", dither @ 5); image.save(type @ "jpeg"); convolve() Convolves the image with the specified filter.
Syntax crop( [Xs @ , ] [Ys @ , ] [Xo @ ] [Yo @ ] [layers @ <"layer list">] // (PSD files only) [PadColor @ ] [PadIndex @ ] [Transparency @ ] [Alg @ <"Normal", "BackColor", "Color", "Alpha">] ); Parameters Xs and Ys - specify the size of the resulting image.
digimarcDetect() Returns true if the object includes embedded Digimarc information. Otherwise returns false. Syntax digimarcDetect(); Parameters There are no parameters for this function. Example var Image = new Media(); Image.load(name @ "peppers.jpg"); if (Image.digimarcDetect() == true) { // Do something if a watermark is dected Image.drawText(font @ "Arial", style @ "Bold", text @ "A DigiMarc watermark has been detected!", size @ 20); Image.
Parameters The following table describes the parameters taken by this method. • • • • • 70 Chapter 3 Parameter Description Type This indicates the type of digimarc you wish to embed. The default is “basic”. Other options are “image”, “transaction”, and “copyright”. The type determines which set of additional parameters that are valid for the watermark. CreatorID A number which uniquely identifies the creator of the image.
Example var image = new Media(); image.load(name @ "peppers.tga"); image.digimarcEmbed(Type @ "transaction", CreatorID @ 404407, CreatorPin @ 32, DistributorID @ 2591, DistributorPin @ 1355, TransactionID @ 667, Adult @ true, Restricted @ true, CopyProtected @ true, Durability @ 16); image.save(type @ "jpeg"); discard() Removes the designated Media object from memory. This function fully supports CMYK image operations. Syntax discard() Example var image = new Media(); image.load(name @ "peppers.
[Opacity @ ] [X @ ] [Y @ ] [HandleX @ <"left", "center", "right">] [HandleY @ <"top", "middle", "bottom">] [Angle @ ] [Smooth @ ] [SmoothFactor <0 .. 4>] [BaseLine @ ] [spacing @ <+ or ->] [Kern @ ] [Line @ ] [Blend @ <"blend-type">] [Tile @ ] [Append @ ] [ClearType @ ] //(windows only) [Dpi @ <0.0...10000.
• “extrabold” or “ultrabold” (“extra” or “ultra” are also acceptable) • “heavy” or “black” Other Style parameter values are “Underline”, “Italic” or “Italics”, and “Strikethru” or “Strikeout”). NOTE: You can combine Style parameter values. For example: Style @ “Bold Italic” Text - specifies the text to be drawn. The text string must be enclosed in quotes. To indicate a line break, insert \n into the text. Color - specifies the color to be used for the text.
SmoothFactor - specifies the power of two for image scale-based smoothing. If “1” is specified, the text will be drawn at twice the specified size and scaled down. If “2” is specified, the text is drawn at four times the size. This scaling produces smoother text for renderers with poor anti-aliasing at smaller text sizes. The Smooth parameter must be set to “true” for this parameter to have any effect. Baseline - if specified, the text is treated as though it is always the height of the largest character.
Example var image = new Media(); image.load(name @ "logobg.tga"); image.drawText(Font @ "Arial", Style @ "Bold", Text @ "MediaScript: Breakthrough Technology", Size @ 18, Color @ 0x0000FF, x @ 185, y @ 30, Smooth @ true, Kern @ true); image.save(type @ "jpeg"); dropShadow() Adds a drop shadow to the image based on its alpha channel. The effects are best seen when compositing the results onto another image. This function fully supports CMYK image operations.
Opacity - defines the level of transparency for the shadow. The default opacity is 255, which is completely solid. The shadow affects the alpha channel of the image as well as the visible channels. Blur - adds blurring that results in a shadow with a more diffused look. Note, however, that the larger the blur value, the more processing is required. Dx and Dy - specify the offset of the shadow from the original, where positive values shift the shadow down and to the right.
Syntax ellipse( X @ Y @ Rx @ Ry @ [Opacity @ ] [Unlock @ ] [Color @ ] [Index @ ] [Saturation @ ] [PreserveAlpha @ ] [Blend @ <"blend-type">] [Width @ ] [Smooth @ ] [Fill @ ] ); Parameters X - specifies (in pixels) the x axis coordinate for the center point of the ellipse. This parameter is required and has no default value.
PreserveAlpha - if set to true, preserves the alpha channel of the target image as the alpha channel of the resulting image. The default is false. Blend - specifies the type of blending used to combine the drawn object with the images.
equalize() Equalizes the relevant components of the media. Equalization takes the used range of a component and expands it to fill the available range. This can be applied to both indexed and non-indexed images. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see selection(). Syntax equalize( [Brightness @ <-1.00 to 20.00>] [Saturation @ <-1.00 to 20.
Syntax exportChannel( Channel @ <"channelname"> [layers @ <"layer list">] // (PSD files only) ); Parameters Valid channel names are: • • • • “Blue”, “Green”, “Red”, “Alpha”, “Cyan”, “Magenta”, “Yellow”, “Black” (CMYK-space) “Brightness”, “Saturation”, “Hue” (HSV-space) “Brightness2”, “Saturation2”, “Hue2” (HLS-space) The default value is Blue. layers - for PSD files, specifies the layers to be exported. The layer numbers begin at 0 (background) and go up. For more information see “load()” on page 101.
flip() Flips the media vertically or horizontally. This function fully supports images within the CMYK color space. Syntax flip( Axis @ <"Horizontal, Vertical"> [layers @ <"layer list">] // (PSD files only) ); Parameters Axis - designates along which axis (horizontal or vertical) to flip the media. layers - for PSD files, specifies the layers to be affected. The layer numbers begin at 0 (background) and go up. For more information see “load()” on page 101. Example var image = new Media(); image.
Parameters Source - specifies the image to add by its user-defined Media object name.If you are adding an image that you have not yet loaded, use the Name parameter to refer to that image by its name and extension (such as “airplane.jpg”). Name - if you or the administrator has set up virtual file systems, you can use this parameter to add frames from that file system. Virtual file systems are defined in the MediaRich server’s local.properties file. See the MediaRich Administrator’s Guide for more information.
Example if (image.getBytesPerPixel() == 3) {... NOTE: If you want MediaRich to return the bit-depth of the image, use the getImageFormat() function. getFrame() Returns a Media object for the specified frame (if available), otherwise returns “undefined”. Syntax .getFrame( ); Parameters This function takes the specified frame offset (starting from 1) as an argument. Example var image = new Media(); image.load(name @ "Images/clock.
Example if (image.getHeight() == 480) {... getImageFormat() Returns a string representing the image type: “8 Bit Palette”, “8 Bit Grayscale”, “15 Bit 5-5-5”, “16 Bit 5-6-5”, “16 Bit 1-5-5-5”, “18 Bit 6-6-6”, “24 Bit”, “32 Bit RGBA”, “32 Bit HSV”, “32 Bit HLS”, or “Undefined”. NOTE: GetImageFormat() has been deprecated. getPixelFormat() is the preferred function and will be supported in future versions of MediaScript. Syntax .getImageFormat(); Parameters This function has no parameters.
Parameters layer number - specifies the desired layer of the Media object. Example var image = new Media(); var newimage = new Media(); newimage = image.getLayer(2); getLayerBlend() Returns the blending mode of the media layer with the specified layer index (if available). Syntax .getLayerBlend( ); Parameters layer index - specifies the desired layer index (starting from 0).
getLayerEnabled() Returns true if the named layer is enabled (visible), false if not. If you use the collapse() function without naming specific layers, MediaRich collapses all enabled layers and ignores disabled layers. Use the getLayerEnabled() function to determine if a layer is enabled or not. Use the setLayerEnabled() function or the eye icon in Photoshop to enable/disable a layer. Syntax .
Syntax .getLayerHandleY( ); Parameters layer index - specifies the desired layer index (starting from 0). Example var image = new Media(); image.load(name @ "peppers.psd"); if(image.getLayerHandleY(0) == "Middle") {... getLayerIndex() Returns the index of the media layer with the specified layer name (if available). Syntax .getLayerIndex( <"layer name"> ); Parameters The only parameter specifies the desired layer name. Example var image = new Media(); image.
Example var image = new Media(); image.load(name @ "peppers.psd"); if(image.getLayerName(2) == "GreenPepper") {... getLayerOpacity() Returns the opacity of the media layer with the specified index (if available). For more information about opacity settings, see “composite()” on page 63. Syntax .getLayerOpacity( ); Parameters layer index - specifies the desired layer index (starting from 0). Example var image = new Media(); image.load(name @ "peppers.psd"); if(image.
getLayerY() Returns the Y offset of the media layer with the specified index (if available). NOTE: X and Y layer offsets determine relative positions of layers to each, and are used by the collapse() function. Syntax .getLayerY( ); Parameters layer index - specifies the desired layer index (starting from 0). Example var image = new Media(); image.load(name @ "peppers.psd"); if(image.getLayerY(2) == 25) {...
Example #include "sys:color.ms" . . . var colors = media.getPalette(); if (colors.length >= 1) { var rgb = new RGBColor(colors[0]); print("red is " + rgb.red); } getPaletteSize() Returns the number of colors in the palette or 0 if the image does not have a palette. Syntax var nColors = .getPaletteSize(); Parameters This function has no parameters. getPixel() Returns the color value, omitting any alpha channel. For RGB images, this will be a 24-bit color value.
getPixelFormat() Returns a string representing the image type: “Gray-8”, “RGB-15”, “RGB-16”, “RGBA-16”, “RGB-18”, “RGB-24”, “RGBA-32”, “HSV-24”, “HLS-24”, “CMYK-32”, “CMYKA-40”. Syntax .getPixelFormat(); Parameters This function has no parameters. Example var image = new Media(); image.load(name @ "peppers.psd"); if(image.getPixelFormat() == "RGB-24") {... getPixelTransparency() Returns the value for the alpha channel or 255 if there is no alpha channel.
layers - for PSD files, specifies the layers to be included. The layer numbers begin at 0 (background) and go up. For more information see “load()” on page 101. Example var image = new Media(); image.load(name @ "peppers.psd"); if(image.getPopularColor()== rgb(255,0,0)) {... getResHorizontal() Returns the horizontal resolution in DPI. Syntax .getResHorizontal(); Parameters This function has no parameters. Example if (image.getResHorizontal() == 72) {...
getWidth() Returns the horizontal size in pixels. Syntax .getWidth(); Parameters This function has no parameters. Example if (image.getWidth() == 480) {... getXmlInfo() Returns an xml document contain the installed file formats. This document looks like following: format name format version comma separated list of extensions\n"; read,write ...
However, if the object has no set background color, MediaRich does the following: • For objects with 256 colors or less, MediaRich uses the first color index • For objects with 15-bit or greater resolution (including the CMYK color-space), MediaRich uses black If the object has no set foreground color, MediaRich does the following: • For objects with 256 colors or less, MediaRich uses the last color index • For objects with 15-bit or greater resolution (including the CMYK color-space), MediaRich uses white
Example var image = new Media(); var image2 = new Media(); image.load(name @ "peppers.tga"); image2.drawText(font @ "Arial", style @ "Bold", text @ "Fresh Peppers!", angle @ 0, color @ 0x00ccff, size @ 36, smooth @ true, baseline @ false, kern @ true); image2.glow(Blur @ 4, Size @ 8, Halo @ 0, Opacity @ 220, Color @ 0xFFFF00, ResizeCanvas @ false); image.composite(source @ image2); image.save(type @ "jpeg"); gradient() Composites a color gradient onto the source image.
[opacity=] [blend=] [layers @ <"layer list">] // (PSD files only) Parameters adjust - when specified, all the other parameters except color1, color2, gradient, and reverse (which have their usual meaning) are ignored. The image is then interpreted as a grayscale image which is then passed through the specified gradient, giving a new false-color image. This operates the same way as the GradientMap adjustment layer in Photoshop. style - specifies a common style for the gradient.
importChannel() Imports the specified source image (treated as a grayscale) and replaces the selected channel in the original. It is important that both images must be the same size. Before you can import an image, you must load() it. NOTE: This function was formerly named importGun(), which has been deprecated. NOTE: Color value parameters to functions supporting CMYK are interpreted as CMYK colors if the raster to which they are applied is CMYK.
infoText() Returns the information about text. Syntax infoText( [font @ <"font">], [size @ <"size">], [style @ <"style">]) Return Values ascent - the font ascent.
Other Style parameter values are “Underline”, “Italic” or “Italics”, and “Strikethru” or “Strikeout”). NOTE: You can combine Style parameter values. For example: Style @ “Bold Italic” line() Draws a line across the image based on the specified parameters. This method accepts all composite() parameters except HandleX and HandleY. The foreground color may vary with this function, depending on the original Media object.
Opacity - specifies opacity of the drawn object. The default value is 255 (completely solid). Unlock - if set to “true”, causes the line to display only where the specified color value appears in the current (background) image. The default is false. Color - specifies the color of the line. Index - colorizes the line using the available color palette from the source image (as an alternative to the Color parameter). NOTE: You cannot specify values for both the Color and Index parameters.
load() Loads an image into the Media object from the specified file. The following file formats support the CMYK color-space: “.psd”, “.tif”, and “.jpg”. NOTE: In MediaRich version 3.6, load() no longer does any color conversion. For instance, additional parameters for Color Profile Specifications srcProfile, destProfile, and intent parameters are no longer supported. You must now explicitly call convert() or colorConvert() to change the type of an image. Syntax load( [name @ <"filename", "http://server_name/.
detect - indicates that if a matching file type is not found, or if the load returns with a FileMangled or FileTypeWrong error, the system will attempt to automatically determine the file's type and load it accordingly. LoadMetadata - if specified as “true”, any Exif, IPTC, or XMP Metadata associated with the image is loaded. The default is “false”. For more information about MediaRich’s metadata support, see Appendix A, “MediaRich Metadata Support.
layers - loads the specified layers. Specify the layers to collapse and the order in which to collapse them. The layer numbers begin at 0 (background) and go up. To specify all layers (including non-visible layers) use the wild-card notation “*”. The visibleOnly() function may used to load only the visible layers of a PSD file. NOTE: MediaRich loads only the image data from the layers and ignores all other effects. To preserve such effects, merge the effects into the layer data in Photoshop.
loadAsRgb() The loadAsRgb() function is an add-on to the Media object that acts exactly like load() does when an RGB file is read. When a CMYK file is read, the images in the file are converted to RGB. This function is defined in Sys/media.ms. Syntax loadAsRgb( [name @ <"filename">] [type @ <"typename">] [detect @ ] [transform @ ] // (FPX files only) [layers @ <"layer list">] // (PSD files only) [fillalpha @ ] // (PNG files only) [screengamma @
makeCanvas() This function creates a “blank” Media object of the specified dimensions and fully supports the CMYK color-space. Syntax makeCanvas( [Xs @ ] [Ys @ ] [Rtype @ ] [FillColor @ ] [Transparency @ ] Parameters Xs and Ys - specify the width and height of the canvas in pixels. If Xs or Ys is not specified, a 1x1 canvas is created.
makeText() This command, instead of compositing text onto the target image, creates a new image that includes just the text. The image produced is always 32-bit. This function fully supports the CMYK color-space. NOTE: Using makeText() within a JavaScript for loop can result in initially poor anti-aliasing. To maintain optimal anti-aliasing, place the text object outside the loop.
Weight modifiers modify the weight (thickness) of the font. Valid weight values, in order of increasing thickness, are: • • • • • • • • • “thin” “extralight” or “ultralight” “light” “normal” or “regular” “medium” “semibold” or “demibold” (“semi” or “demi” are also acceptable) “bold” “extrabold” or “ultrabold” (“extra” or “ultra” are also acceptable) “heavy” or “black” Other Style parameters are “Underline”, “Italic” or “Italics”, and “Strikethru” or “Strikeout”.
Wrap - if specified, its value forces a new line whenever the text gets longer than the specified number of pixels (in this case correct word breaking is used). Angle - allows the text to be rotated clockwise by the specified angle (in degrees). Line - specifies the line spacing. The default spacing between lines of text is 1.5. Smooth - specifies that the text is drawn with five-level anti-aliasing. SmoothFactor - specifies the power of two for image scale-based smoothing.
measureText() Returns an array of offsets where each character would be drawn for a single line of text. If more that one line of text is specified (by including “\n”) then only the first line of text is measured. This method is available for Windows only. Syntax measureText( [text @ <"string">], [font @ <"font family">], [size @
Other Style parameters are “Underline”, “Italic” or “Italics”, and “Strikethru” or “Strikeout”). NOTE: You can combine Style parameters. For example: Style @ “Bold Italic” Text - specifies the text to be drawn. The text string must be enclosed in quotes. To indicate a line break, insert \n into the text. Size - sets the point size of the font to be used. The default size is 12. Spacing - adjusts the spacing between the text characters. The default is 0.
otherHighPass() Applies an effect opposite that of blurGaussianBlur() — it replaces each pixel with the difference between the original pixel and a Gaussian-blurred version. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax otherHighPass( [Radius @
Syntax otherMaximum( [Radius @ ] ); Parameters Radius - determines the extent of the effect. The default is 1 (minimal effect). Example var image = new Media(); image.load(name @ "peppers.tga"); image.otherMaximum(Radius @ 2); image.save(type @ "jpeg"); otherMinimum() Replaces the pixels within the radius with the darkest pixel in that radius, thereby amplifying the darker areas of the image.
Example var image = new Media(); image.load(name @ "peppers.tga"); image.otherMinimum(Radius @ 2); image.save(type @ "jpeg"); pixellateFragment() Makes and offsets four copies of the image. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax pixellateFragment( [Radius @
pixellateMosaic() Pixellates the image, with pixel size determined by the Radius parameter. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax pixellateMosaic( [Size <2..64>] ); Parameters Size - determines the resulting pixel size. The default is 8. Example var image = new Media(); image.load(name @ "peppers.tga"); image.
Syntax polygon( Points @ <"x,y;x,y;x,y;x,y">, [Opacity @ ] [Unlock @ ] [Color @ ] [Index @ ] [Saturation @ ] [PreserveAlpha @ ] [Blend @ <"type">] [Width @ ] [Smooth @ ] [Fill @ ] Parameters Points - describes each point of the polygon, using absolute coordinate points. Each pair of coordinates is separated from the next by a semicolon.
Width - specifies the thickness (in pixels) of the line that describes the polygon. The default is 1. NOTE: If the Fill parameter is set to true, Width is ignored. Smooth - if set to “true”, makes the edges of the polygon smooth, preventing a pixellated effect. The default is false. Fill - if set to “true”, fills in the polygon with the color specified by the Color or Index parameter. The default is false. Example var image = new Media(); image.load(name @ "logobg.tga"); image.
Parameters Smooth - provides for smooth edges when warping the image using non-right angles. TopLeftX and TopLeftY - represent the upper left corner of the area to be warped. The default is the original image’s upper-left corner. TopRightX and TopRightY - represent the upper right corner of the area to be warped. The default is the original image’s upper-right corner. BotLeftX and BotLeftY - represent the lower left corner of the area to be warped. The default is the original image’s lower-left corner.
Syntax rectangle( X @ , Y @ , Xs @ , Ys @ , [Opacity @ ] [Unlock @ ] [Color @ ] [Index @ ] [Saturation @ ] [PreserveAlpha @ ] [Blend @ <"blend-type">] [Width @ ] [Angle @ ] [Smooth @ ] [Fill @ ] ); Parameters X - indicates (in pixels) the x axis coordinate of the upper left corner of the rectangle.
PreserveAlpha - if set to “true”, preserves the alpha channel of the target image as the alpha channel of the resulting image. The default is false. Blend - specifies the type of blending used to combine the drawn object with the images.
Parameters Netscape - if set to “true”, applies the Netscape default palette as an alternative to applying the default custom palette. BW - if set to “true”, applies the two-color, black and white palette. Pad - ensures that the palette always contains the required number of colors. In a situation where there are fewer unique colors in the image than required for the palette, the extra colors are padded with black.
MediaRich also allows you to set up virtual file systems and then use the Name parameter to load palettes from a virtual file system. Virtual file systems are defined in the MediaRich server’s local.properties file. For example, if you define “MyPalettes:” to represent the path “C:/PALS/MyPalettes/” in the local.properties file, you can use files from the MyPalettes directory with the reduce() function: image.reduce(name @ "MyPalettes:/custom.
rotate() Rotates the media by the specified angle in degrees. This function fully supports the CMYK color-space. Syntax rotate( Angle @ [ResizeCanvas @ ] [Smooth @ ] [Xs @ ] [Ys @ ] [layers @ <"layer list">] // (PSD files only) ); Parameters Angle - specifies the number of degrees the image will be rotated. Positive numbers rotate clockwise and negative numbers rotate counter-clockwise.
rotate3d() Rotates the image in 3D along either the x-axis or y-axis. A positive angle rotates away from the viewer about the top or left edge, a negative angle rotates away from the viewer about the bottom or right edge. This function fully supports media objects within the CMYK color-space.
Example var image = new Media(); image.load(name @ "pasta.tga"); image.rotate3d(angley @ 30, distance @ 28); image.save(type @ "jpeg"); save() Saves a Media object to the specified file. You can save the Media object as a BMP, EPS, GIF, JPEG, PCX, PDF, PICT, PNG, PPM, PSD, SWF, TIFF, TGA, or WBMP. Syntax save( [name @ "ftp://username:password@ftp.server_name/..
Parameters name - specifies the name used to save a file to an FTP URL. image.save(name@"ftp://jdoe:ax24z87@ftp.equilibrium.com/ test.gif"); NOTE: FTP support is disabled by default for security reasons. Contact your MediaRich Administrator to enable this functionality. image.save(name@"ftp://jdoe:ax24z87@ftp.equilibrium.com/ test.gif"); type - specifies the file type of the saved image; otherwise, the type is derived from the extension of the file name.
• ManualUnspecified - this mode disables any compression to allow compatibility with any applications that do properly follow the GIF specification. • ManualLeave - this mode prevents the disposal of the preceding frame when displaying the current frame. • ManualUseBG - this mode replaces the preceding frame with the background color usually transparent - when displaying the current frame. • ManualUsePrev - this mode restores the preceding frame before displaying the next frame.
previewAtEnd – if set to “true”, writes the TIFF preview at the end of the file. If not specified, it defaults to “false” and writes the TIFF preview at the beginning of the file. Additional Parameter for TIFF Files endian - indicates the byte order. Values of “big”, “mac”, “motorola”, and “sparc” save the data in big-endian byte order. “little”, “pc”, “intel”, and “x86” save the data in littleendian byte order. Compression - indicates the compression scheme to use.
scale() Scales the image to the specified size. This function fully supports the CMYK color-space. Syntax scale( [Alg @ <"Fast", "Smooth", "Outline", "Best">] [Constrain @ ] [Xs @ , ] [Ys @ , ] [X1 @ ] [Y1 @ ] [X2 @ ] [Y2 @ ] [PreserveBackground @ ] [PreserveBackgroundCutoff @ ] [PadColor @ ] [PadIndex @ ] [Transparency @
PreserveBackgroundCutoff - specifies the threshold for PreserveBackground. The default threshold percentage is 67%, which means that the background color will be preserved unless 67% or more of the pixels use the background color. Padcolor or Padindex - specifies the color to be used where the new image dimensions extend beyond the current image. If a pad color is not specified, the image’s background color is used by default. For more information about setting an image’s background color, see setColor().
This function can be used in conjunction with the following functions: adjustHsb(), adjustRgb(), blur(), blurBlur(), blurGaussianBlur(), blurMoreBlur(), blurMotionBlur(), colorize(), composite(), equalize(), noiseAddNoise(), otherHighPass(), otherMaximum(), otherMinimum(), pixellateMosaic(), pixellateFragment(), sharpenSharpen(), sharpenSharpenMore(), sharpenUnsharpMask(), stylizeDiffuse(), stylizeEmboss(), stylizeFindEdges(), and stylizeTraceContour().
The color can be specified as the background color, or as all pixels of a specified color, index value, or color type. In the event that a selection containing everything except a particular color is required, the “invert” parameter can be added to the command. Invert - reverses the opacity values of the current selection (for example, 0->255 and 255->0). NOTE: If the invert parameter is used, it will invert both the opacity and the backcolor, color, and index values.
• For all other images: Background color will be black. Foreground color will be white. NOTE: If the image’s file type supports them and its background, transparency and/or foreground colors have been set, those values will be used. Unless specifically changed, the initial values will be retained and used throughout all subsequent transformations. To be sure of the values used, it is best to use specific settings.
Example var image = new Media(); image.load(name @ "car.tga"); image.setColor(backcolor @ 0xC2270B); image.crop(alg @ "backcolor"); image.save(type @ "jpeg", compressed @ true); setFrame() Replaces the Media object for the specified frame (if available). Can be used with getFrame() to modify an animation. Syntax .
setLayer() Replaces the Media object for the specified layer (if available). Used in conjunction with getLayer(), this is commonly used to modify layer contents before calling the collapse() function. Syntax .setLayer( ); Parameters The first parameter represents the layer index (the first layer in a file is layer 0). The second parameter names the Media object that contains the data with which the layer is replaced.
setLayerEnabled() Sets the specified layer as either enabled or disabled. If you use the collapse() function without naming specific layers, MediaRich collapses all enabled layers and ignores disabled layers. Use the setLayerEnabled() function or the eye icon in Photoshop to enable/disable a layer. Use the getLayerEnabled() function to determine if a layer is enabled or not. Syntax .
setLayerHandleY() Sets the HandleY of the media layer with the specified index (if available). Syntax .setLayerHandleY( <"position"> ); Parameters The first parameter specifies the desired layer index (starting from zero). The second parameter sets the selected layer’s attachment point on the x-axis. The default is “Middle”. Other options are “Top” and “Bottom”. Example var image = new Media(); image.
Parameters The first parameter specifies the layer in the target image that gets its pixels replaced. The default is the first layer (starting from zero). The second parameter specifies the source Media object. Before you can use setLayerPixels() you must load() the source image. If the source image has multiple layers, the first one is used. Example var Target = new Media(); var Source = new Media(); Target.load (name @ "banner.psd"); Source.load (name @ "fishes.psd"); Target.setLayerPixels(3,Source); Target.
The second parameter specifies the position of the selected layer along the y-axis of the composite image, with the layer’s center point used as the anchor point. For example, a value of 100 positions the center point at pixel 100 on the y-axis of the composite image. Example var image = new Media(); image.setLayerY(2, 100); setLayerPixels() Sets the image in the specified layer of the current media to the specified raster. Syntax .
setPixel() Sets the color of one pixel to the chosen color value. This works in both RGB and CMYK color spaces. Syntax .setPixel( [x @ <"pixel">] [y @ <"pixel">] [transparency @ 0-255, or true or false] [color @ <"color">] [layers @ <"layer list">] // (PSD files only) ); Parameters: x and y - required parameters that specify the coordinates of the target pixel. The top-left corner of an image is represented by the coordinates 0,0.
if (Image.getPixel(x @ x, y @ y) == FindColor) { Image.setPixel(x @ x, y @ y, rgb @ MakeColor); } } } Image.save(type @ "jpeg") setResolution() Changes the DPI of the image in memory and fully supports media objects within the CMYK color-space. NOTE: This information can be stored only in the following formats: BMP, GIF, JPEG, PCT, PCX, PNG, PSD, and TIFF. Syntax setResolution( [Dpi @ ] [XDpi @ ] [YDpi @
setSourceProfile() Sets the embedded profile for an image to the specified source profile. This profile replaces any existing embedded profile for the image. NOTE: The colorspace of the specified source profile must match the colorspace of the image. Syntax setSourceProfile( sourceProfile @ <"filename.icc"> ); Parameters SourceProfile - specifies the profile to use as the images new embedded profile. For more information about specifying profiles, see “colorCorrect()” on page 59.
sharpenSharpenMore() Sharpens the clarity of an image, similar to the sharpenSharpen() function, but to a greater extent. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax sharpenSharpenMore(); Parameters This function has no parameters. Example var image = new Media(); image.load(name @ "peppers.tga"); image.sharpenSharpenMore(); image.
Threshold - specifies the degree to which a blurred version of a pixel must be different from the original version before the enhancement takes effect. The default is 0. Example var image = new Media(); image.load(name @ "peppers.tga"); image.sharpenUnsharpMask(Radius @ 18, Amount @ 450, Threshold @ 125); image.save(type @ "jpeg"); sizeText() Returns the width, height, and lines for the specified parameters. This function is available on Windows only.
Parameters Font - specifies the TrueType or PostScript font family name to be used, for example, “Arial”. MediaRich supports Type 1 (.pfa and .pfb) PostScript fonts only. NOTE: The size of the font in pixels is dependent on the resolution of the resulting image. If the resolution of the image is not set (zero), the function uses a default value of 72 DPI. The default location for fonts specified in a MediaScript is the fonts file system.
Kern - if set to “true”, optimizes the spacing between text characters. By default this is set to true. If you do not want to use kerning, this must be specified as false. NOTE: PostScript fonts store the kerning information in a separate file with a .afm extension. This file must be present in order for kerning to be applied to the text. ClearType - if specified as “true”, the Windows ClearType text renderer will be used if available.
stylizeEmboss() Makes the image appear as though embossed on paper. NOTE: This function is “selection aware,” so that if a selection has been made, the system applies it based on the current selection. For more information about making selections, see “selection()” on page 129. Syntax stylizeEmboss( [Height @ ] [Angle @ ] [Amount @ ] ); Parameters Height - determines the depth of the embossing effect. The default is 3.
Syntax stylizeFindEdges( [Threshold @ ] [Grayscale @ ] [Mono @ ] [Invert @ ] ); Parameters Threshold - specifies how sharp an edge must be to included. The default is 0. Grayscale - produces a monochromatic result. The default is false. Mono - when set to “true”, causes all edges above the threshold value to default to 255. The default is false. Invert - reverses the default foreground and background colors. The default is false.
Parameters Level - indicates the level of each color gun. The default is 128. Upper - if set to “true”, causes the upper edge to be delineated. The default is false (the lower edge is delineated). Invert - if set to “true”, reverses the default foreground and background colors. The default is false. Example var image = new Media(); image.load(name @ "peppers.tga"); image.stylizeTraceContour(Level @ 96, Upper @ true, Invert @ true); image.
Parameters Alg - specifies the algorithm that will be used. The default algorithm is fast. The outline algorithm should be used for black and white images only. Xs and Ys - specify the destination size of the media. The resulting image always fits these dimensions regardless of the scale and the source media. X and Y - specify the position of the top-left corner of the region to be zoomed. These coordinates are specified relative to the destination media at scale @ 1.
XmlDocument Object MediaRich allows users to interact with XML documents and supports all the objects, properties, and methods of the Document Object Model (DOM) Level 1 Core. The DOM Core is an application programming interface for XML documents. For information on using the DOM Level 1 Core objects, properties, and methods, see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/. NOTE: If your MediaScript uses the Xmldocument object, it must reference the xml.
loadFile() Loads an XML document from the file system. Syntax .loadFile( <"filename.xml", "virtualfilesystem:/filename.xml"> ); Parameters The loadFile() function accepts an XML filename as it’s only parameter. By default, MediaRich looks for XMLDocument files in the write file system which point to the following directory: MediaRich/Shared/Originals/Media NOTE: You can modify the MediaRich server’s local.properties file to change the default Media directory.
Parameters This function accepts an XML filename as its only parameter. By default, MediaRich saves XMLDocument files in the write file system which point to the following directory: MediaRich/Shared/Originals/Media NOTE: You can modify the MediaRich server’s local.properties file to change the default Media directory. See “File Systems” on page 14 for more information. MediaRich also allows you to set up virtual file systems and then save files to that location.
Text Response Object The TextResponse objects allow users to create response objects that take strings and save text files (“plain text”, “html”, or “xml”). TextResponse Object Properties There are no properties for this object.
append() Appends the given text string to the text associated with the named object. Syntax .append( <"text string"> ); Parameters This function takes only a text string, which must be enclosed in quotation marks. getText() Returns the text associated with the named object. Syntax .getText(); Parameters This function has no parameters. getTextType() Returns the text type associated with this object: “TextResponse.TypePlain”, “TextResponse.TypeHtml”, or “TextResponse.
Parameters This function takes only a text string, which must be enclosed in quotation marks. setTextType() Sets the text type associated with this object. (must be one of the defines above). Syntax var strObject = TextResponse( ); Parameters textType - specifies the text type using one of the following predefined values: • TypePlain - saves text as a plain text file with extension .txt. • TypeHtml - saves text as an HTML file with extension .html.
• • • • • IccProfile.LINK IccProfile.ABSTRACT IccProfile.COLORSPACE IccProfile.NAMEDCOLOR IccProfile.UNKNOWN Parameters colorspace -> Bitwise OR (|) of desired colorspace values. class -> Bitwise OR (|) of desired profile class values. Example The following code gets an array of all the ICC monitor and printer profiles for RGB and CMYK colorspaces. #link "IccProfile.dll" var profs = IccProfile.list(IccProfile.RGB | IccProfile.CMYK, IccProfile.MONITOR | IccProfile.
Example The following code creates an IccProfile object using the “USWebCoatedSWOP.icc” profile. #link "IccProfile.dll" var prof = new IccProfile("USWebCoatedSWOP.icc"); var image = new Media(); image.load(name @ "fileWithEmbeddedProfile.jpg"); var prof2 = new IccProfile(image); getName() Returns the friendly display name of the profile. Parameters This function takes no parameters. Example The following code creates an IccProfile object using the “USWebCoatedSWOP.icc” profile and gets the friendly name.
Example The following code creates an IccProfile object using the “USWebCoatedSWOP.icc” profile and tests if it is a printer profile. #link "IccProfile.dll" var prof = new IccProfile("USWebCoatedSWOP.icc"); var isPrinter = prof.getClass() & IccProfile.PRINTER; getColorspace() Returns the profile colorpace. Parameters This function takes no parameters. Example: The following code creates an IccProfile object using the “USWebCoatedSWOP.icc” profile and tests if it is a CMYK profile. #link "IccProfile.
Example The following code creates an IccProfile object using the “USWebCoatedSWOP.icc” profile and then closes the file: #link "IccProfile.dll" var prof = new IccProfile("USWebCoatedSWOP.icc"); prof.close(); IccProfile.dll The following code returns text describing every available CMYK profile: #link "IccProfile.dll" #include "sys:/TextResponse.ms" function main() { var txt = new TextResponse(); var profs = IccProfile.list(IccProfile.CMYK, IccProfile.UNKNOWN); for (var i = 0; i < profs.length; ++i) { txt.
Zip Object The Zip object is used to create and add files to a new zip archive. Zip Profile Object Methods The Zip Object implements the following methods: • Zip(), Constructor • addFile() • save() NOTE: For all paths in the Zip Object that do not specify a file system the default is the write file system. See “File Systems” on page 14 for more information. Zip() Constructor for Zip object. Parameters This function takes no parameters. addFile() Adds a file to the zip archive.
Unzip Object The Unzip object is used to extract files from an existing zip archive. Unzip Profile Object Methods The Unzip Object implements the following methods: • • • • • • • • Unzip() constructor open() extractAll() firstFile() nextFile() getFileName() extractFile() close() NOTE: For all paths in the UnZip Object that do not specify a file system the default is the read file system. See “File Systems” on page 14 for more information. Unzip() Constructor for Unzip object.
firstFile() Resets file iterator to first file in archive. Returns a string with the name of current file, or null if not found. Parameters This function takes no parameters. nextFile() Advances file iterator to next file in archive. Returns a string with the name of current file, or null if not found. Parameters This function takes no parameters. getFileName() Returns name of current file in archive. Parameters This function takes no parameters. extractFile() Extracts the current file to the specified file.
To extract each file individually: var myZip = new Unzip(); myZip.open("zip/files.zip"); var filename = myZip.firstFile(); while (filename != null) { myZip.extractFile("files/" + filename); filename = myZip.nextFile(); } myZip.close(); Global Functions MediaRich supports all the basic ECMAScript capabilities, including conditionals, variables, functions, and exception handling, as well as the proprietary image processing functions described here.
Multi-Frame Parameters Multi-frame files (such as GIF and TIFF) are a special case, because the files contain more than one frame. MediaScript supports a “frames” parameter that can be included with all transform commands for processing specific frames within a multi-frame file. NOTE: Multi-frame parameters can be used with the save() command, but not the load() command. frames - specifies a single frame, or a complex group of frames using a frame list.
The global functions, CmykColor, RgbColor, and LoadAsRGB are defined in “Sys/color.ms”. CmykColor This object is constructed from a 32-bit value. It splits the color into cyan, magenta, yellow, and black components. Constructor CmykColor(value) - returns an CmykColor object constructed from value. Properties .cyan - the cyan component (read or write). Valid values range from 0 to 255. .magenta - the magenta component (read or write). Valid values range from 0 to 255. .
Examples The following script uses the MediaGenClient COM object to call another MediaScript. function main() { var mgen = COMCreateObject("MediaGenClient.MGClient"); mgen.ScriptName = "testtext.ms"; mgen.SetParameter("args", 20); mgen.ExecuteScript(); mgen.SaveBuffer(System.getNativePath("write:/comsave.jpg")); resp.setPath("write:/comsave.jpg"); } NOTE: This example is not generally recommended as it can cause deadlocks. It is provided for instructional purposes only.
getScriptFileName() Returns the current filename for this running script. Syntax getScriptFileName(); print() Depending on the platform, prints the specified string to the command prompt (MS Windows) or to MediaScript log (Mac OS). Syntax print (<"string">); rgb() Converts the three supplied RGB color values into a 24-bit value (0 - 16,777,215) that is suitable for many Media() graphic operation arguments.
Examples #include "Sys/color.ms" myColor = new RgbColor(0x1133aa); print (myColor.red, myColor.green, myColor.blue); myColor = new RgbColor(); myColor.red = 27; myColor.green = 59; myColor.blue = 255; media = new Media(); media.makeCanvas(xs @ 100, ys @ 100, fillcolor @ myColor); version() Returns a string that is the current version of MediaScript.
Appendix A MediaRich Metadata Support •••••• MediaRich provides support for the most popular metadata formats: IPTC, Exif, and XMP. MediaRich fully supports loading, saving and merging IPTC, Exif, and XMP metadata for JPEG, TIFF, and Photoshop files. MediaRich also supports loading XMP metadata from the following file formats: Illustrator, EPS, GIF, PDF, and PNG. This metadata is available to the script as a metadata XML document.
Low-Level Metadata Interface Two MediaScript objects provide support for metadata: The Media object and the _MR_Metadata object. The Media object provides support for loading and saving metadata along with the image contents. The _MR_Metadata object provides support for loading and merging just the metadata contained within the files, without loading the image data. This allows the scripter to modify the metadata within compressed files without decompressing and recompressing the image data.
The _MR_Metadata constructor takes a file name and an optional file type. var metaObj = new _MR_Metadata(“myimage.jpg”, “jpeg”); If the file has a valid extension, the file type may be omitted. The _MR_Metadata save command provides a single object as a parameter, in a manner similar to the Media object save command. This parameter may be specified as an object, or using the ampersand ("@") notation. The parameters for the save command object are exif, iptc, xmp, and name.
High-Level Support for Exif and IPTC Two MediaScript objects are provided to simplify the tasks of getting and setting individual metadata items. These objects are provided to support IPTC and Exif metadata. Each of these objects has a similar format, providing set methods and get methods which set and get individual metadata fields, respectively. represents the name of the metadata tag to set or get.
{ // file did not contain metadata. } Alternatively, you can simply use the get methods, which will return null if the document is empty. IPTCMetadataObject The following methods may be used to get and set metadata values for IPTC metadata. Please refer the schema (IPTC.xsd) in the //Shared/Originals/Sys folder for the required format for each of the IPTC fields. Note that only a brief description is provided here.
• • • • • 174 Method Description addSubjectReference(string, ...) Adds subject references to the list. setSubjectReferenceArray(array) Sets a group of subject references from an Array. getCategory() Returns the category code. setCategory(string) Sets the category code. getSupplementalCategory() Returns the supplemental category array. setSupplementalCategory(string, ...) Sets supplemental categories. addSupplementalCategory(string, ...) Adds a value to the supplemental category list.
Method Description setSpecialInstructions(string) Sets the SpecialInstructions field. getActionAdvised() Returns the ActionAdvised field. setActionAdvised(string) Sets the ActionAdvised field. getReference() Returns an array of Reference object for the Reference field. Each reference object has a ReferenceService, ReferenceDate, and ReferenceNumber property. getReferenceService(which) Returns the ReferenceService property of the Reference element indexed by which.
• • • • • 176 Method Description getByLine() Returns an array of ByLine objects, each of which contains a ByLineWriter and a ByLineTitle property. getByLineWriter(which) Returns the ByLineWriter property of the ByLine element specified by which. getByLineTitle(which) Returns the ByLineTitle property of the ByLine element specified by which. setByLine(writer, title) Sets the ByLine element to the specified writer and title.
Method Description getCaption() Returns the Caption element. setCaption(string) Sets the Caption element. getWriter() Returns an array of writer elements. setWriter(string, ...) Sets Writer elements. addWriter(string, ...) Adds Writer elements. setWriterArray(array) Sets Writer elements from an array. getImageType() Returns the ImageType. setImageType(string) Sets the ImageType. getImageOrientation() Returns the ImageOrientation. setImageOrientation(string) Sets the ImageOrientation.
Method Description setDateTime(date) Sets the DateTime field from a MediaScript Date object. getPhotographerCopyright() Returns the photographer copyright. setPhotographerCopyright(string) Sets the photographer copyright. getEditorCopyright() Returns the editor copyright. setEditorCopyright(string) Sets the editor copyright. getMake() Returns the camera make. getModel() Returns the camera model. getImageWidth() Returns the image width. getImageLength() Returns the image height.
Method Description getPixelXDimension() Returns the width. getPixelYDimension() Returns the height. getComponentsConfiguration() Returns the ComponentsConfiguration value. getCompressedBitsPerPixel() Returns the approx. number of compressed bits per pixel. getRelatedSoundFile() Returns the name of a related sound file. getDateTimeOriginal() Returns a MediaScript Date object for the original date/time. getDateTimeDigitized() Returns a MediaScript Date object for the digitized date/time.
• • • • • 180 Method Description getFocalPlaneResolutionUnit() Returns the focal-plane resolution unit. getSubjectLocation() Returns the subject location. getExposureIndex() Returns the exposure index. getSensingMethod() Returns the sensing method. getFileSource() Returns the file source. getSceneType() Returns the scene type. getCFAPattern() Returns the CFA pattern.
Appendix B MediaRich Color Management •••••• MediaScript uses the ICC (International Color Consortium) methodology for color management, where the color characteristics of each color reproduction device to be used is stored in a color profile. This appendix explains the basics of color management and how to use MediaRich and the MediaScript scripting language to insure accurate RGB and CMYK color conversions.
Color Management Overview MediaScript uses the ICC (International Color Consortium) methodology for color management, where the color characteristics of each color reproduction device to be used is stored in a color profile. Converting an image from one device to another involves setting up a color transformation between the source profile and the destination profile. This transformation is then used to convert each pixel in the image from the source device to the destination device.
White Point Mapping The color considered to be “white” on each device may not be the same. What is considered “white” for CMYK devices depends on the paper being used, while “white” on a monitor depends on the maximum intensities of the red, green, and blue channels. Typically, monitors have a “white” that is noticeably bluer than paper. However, when an image displayed on the screen is printed, one does not typically expect the image to be printed on a blue background.
mapped to the same color on the destination device. This intent is useful when it is known that the colors in the image mainly lie inside the gamut of both the source and the destination device. Absolute Colorimetric This intent is used when you want the colors on the destination device to be colorimetrically equal to that on the source device. No white point mapping is done. This intent is rarely used for image processing.
Profile Management methods With the exception of the load and save methods of the Media object, the profile management methods are contained in the IccProfile link object. Media Object The load() method of the Media object automatically loads any embedded source profiles for supported file formats. The save method can optionally embed the color profile associated with an image along with the image data for supported file formats.
list() The list method is a static method that returns an array of profile names that match specified class and colorspace criteria. This method may be used for example to return a list of all Monitor profiles that have an RGB colorspace. Specifying Profiles The methods colorCorrect, colorFromImage, colorToImage, and setSourceProfile all take a SourceProfile argument, a DestProfile argument, or both. There are three methods for specifying these profiles: • Specify the path to a profile on disk.
Because of the inherent inaccuracy in the color conversion process, converting from one colorspace to another and back should also be avoided where possible. Images for processing should be converted to a common colorspace, processed, and converted to the destination. Choice of the common colorspace depends on the colorspace of the images involved, the type of images involved, the quality of the color profiles, the destination colorspace, and the operations to be performed.
What’s the best method for color correcting a Grayscale image? To maintain compatibility with previous versions of MediaRich, Grayscale images may be treated in the same manner as RGB images. However, this assumes that the default RGB colorspace uses equal amounts of red, green, and blue to represent gray, and that the transform from Grayscale to RGB is linear.
Index •••••• Crosshatch 203 Dark Strokes 203 Ink Outlines 204 Spatter 205 Sprayed Strokes 206 Sumi-e 207 Symbols #include 30 #link 31 A Accented Edges 201 adjustHsb() 65 adjustRgb() 66 Angled Strokes 202 append() 170 arc() 67 Artistic Filters 187 Colored Pencil 188 Cutout 188 Dry Brush 189 Film Grain 190 Fresco 191 Paint Daubs 191 Palette Knife 192 Plastic Wrap 193 Poster Edges 194 Rough Pastels 194 Smudge Stick 196 Sponge 196 Underpainting 197 Watercolor 198 B Bas Relief 221 blank canvas 121 Blur plug
custom file system aliases 33 Cutout 188 D Dark Strokes 203 Database object 31, 179 databases interacting with 179 working with 31 DeBabelizer 142 De-Interlace 240 Difference Clouds 220 Diffuse Glow 208 Digimarc support digimarcDetect() 85 digimarcEmbed() 85 directives #include 30 #link 31 discard() 87 Distort plug-in filters Diffuse Glow 208 Glass 209 Ocean Ripple 210 Pinch 211 Polar Coordinates 211 Ripple 212 Spherize 213 Twirl 213 Wave 214 ZigZag 215 DPI resolution 156 drawing methods arc() 67 drawText(
stylizeEmboss() 162 stylizeFindEdges() 162 stylizeTraceContour() 163 fixAlpha() 96 flip() 97 FPX files 119 Fresco 191 FSNet file systems 38 FTP support 117 getScriptFileName() 183 print() 183 rgb() 183 version() 184 glow() 109 Glowing Edges 232 Gradient 111 Grain 236 Graphic Pen 224 G H getBitsPerSample() 98 getBytesPerPixel() 98 getFileName() 42 getFilePath() 42 getFrame() 99 getFrameCount() 99 getHeight() 99 getImageFormat() 100 getInfo() 100 getLayer() 100 getLayerBlend() 101 getLayerCount() 101 getL
M N makeCanvas() 121 makeText() 122 Media Object components 59–153 clone() 73 embeddedProfile() 94 getBitsPerSample() 98 getBytesPerPixel() 98 getFrame() 99 getFrameCount() 99 getHeight() 99 getImageFormat() 100 getInfo() 100 getLayer() 100 getLayerBlend() 101 getLayerCount() 101 getLayerEnabled() 102 getLayerHandleX() 102 getLayerHandleY() 102 getLayerIndex() 103 getLayerName() 103 getLayerOpacity() 104 getLayerX() 104 getLayerY() 105 getMetaData() 105 getPixel() 106 getPopularColor() 107 getResHorizonta
R Radial Blur 199 read() 45 readNextLine() 45 rectangle() 133 reduce() 135 rename() 45 Render Filters Clouds 220 Difference Clouds 220 resolution 156 Response Types 47 Reticulation 228 rgb() 183 Ripple 212 rmdir() 46 rotate() 138 rotate3d() 139 Rough Pastels 194 S save() 140 scale() 144 selection() 145 setColor() 147 setFrame() 149 setLayer() 150 setLayerBlend() 150 setLayerEnabled() 151 setLayerHandleX() 151 setLayerHandleY() 152 setLayerOpacity() 152 setLayerPixels() 152 setLayerX() 153 setLayerY() 153 s
Stained Glass 238 Texturizer 239 Texturizer 239 TIFF files 143 TIFF preview 142 Tiles 234 Time-to-live 25 Torn Edges 230 transparency 145 Twirl 213 U Underpainting 197 User Profile Information 24 V version() 184 Video Filters De-Interlace 240 NTSC Colors 241 W Water Paper 230 Watercolor 198 watermarks digimarcDetect() 85 digimarcEmbed() 85 Wave 214 WBMP files 119 Wind 234 write() 46 writing files 140 X Xmldocument object 30 XMLDocument Object components 166–168 Z ZigZag 215 zoom() 164 194 MediaRich P