Scripting out of control

Log-in or register.

Scripting out of control

Published by on November 27th 2007.

I had it coming… I should have never unleashed it. The scripting interface in RealWorld Designer took a sharp turn and became a lot more than was originally planned.

Do you want to rotate pictures by EXIF tags? Generate thumbnails and code for html galleries? Watermark and decorate pictures? Or… do it all in one step? Well…why should I care? You can do it yourself using scripts.

Plug-in based scripting?

Almost anything in RW Designer makes use of plug-ins, so why not scripting? A scripting plug-in can do two things: First, it may introduce a global object with methods and properties accessible from script and second, it may make certain functions of a document callable in the script.

An example of the first case is the Blender object, which enables users to create a temporary canvas and combine contents of canvases and real image documents using given blending operation.

An example of the second case is the EXIF interface wrapper, which can be used to manipulate EXIF tags of a document from script.

Interactive scripts

Most of image filters are configurable and it would be silly if scripted operations were not configurable. Fortunately, they are. It is possible to specify a couple of parameters that the user may change when the script is executed. The configuration dialog may contain edit boxes, sliders, color pickers, combo boxes and check boxes. The dialog may also contain a preview window.

The image below is a scripted operation in action. Note the 3 sliders by the bottom edge of the window. Each one of them controls what values are added or subtracted to/from the red, green and blue channels.

Configuration dialog of a scripted operation.

As a side effect, the scripted configuration can be used to limit or customize configuration of an ordinary image filter. You may for example create a sharpening filter (that uses the generic convolution image filter) and is controlled by a single “magnitude” slider.

Example

Let’s have a look at a simple example. Imagine, you have a digital camera that is able to record the orientation of a photo to the EXIF tag (this feature is not uncommon anymore). The following script will automatically rotate the image according to the value of the “Orientation” EXIF tag. It is of course possible to use the operation in batch mode to rotate all your photos at once.

if (Document.EXIF.Exists)
{
    var orientation = Document.EXIF.GetValueByName("Orientation");
    var angle = 0;
    if (orientation == 'bottom - right')
        angle = 180;
    else if (orientation == 'right - top')
        angle = 90;
    else if (orientation == 'left - bottom')
        angle = 270;
    if (angle != 0)
    {
        var rotation = Operation.Create("Raster Image - Rotate");
        rotation.Angle = angle;
        rotation.Resize = true;
        Operation.Execute(rotation, Document);
        Document.EXIF.SetValueByName("Orientation", 'top - left');
    }
}

Is that all?

No, of course not. The possibilities of the updated scripting system are quite numerous and in certain aspects, they even surpass the scripting subsystems of Photoshop or GIMP. You can open, modify and save documents, open new windows, use operations and drawing tools and if everything else fails, you can create your own scripting plug-in.

Recent comments

user icon Anonymous
I wish there were...
Select background
What about ICL files?
Vista & Win 7 icons