Contents | Introduction | JSON | Creating Objects | Playing with Objects | Drawing | Image Filter Chains | Image Metadata | Scripts | Asynchronous Commands and Performance

Scripts

MovingImages comes with a number of scripts. Most of them are installed with the ruby gem and are available immediately after installation. There are a number of scripts which have not been updated to to be implemented using the gem, they are still available and can be downloaded. They are listed further down after the scripts included with the ruby gem.

Every script takes the command line option --help which will return a brief description of the script, it's command line options and a couple of examples.

Scripts installed with ruby gem

The MovingImages ruby gem code is public and can be viewed on github. The scripts themselves are in the bin folder, and the call from the scripts where most of the works is done is a call into the the MILibrary module. For example the addtextwatermark script calls MILibrary.addtextwatermark(@@options, image_list) which is where the work happens in processing the image files.

Many of the scripts have a quality option. This allows you to specify a quality versus image file compression trade off when saving a new image file. This option is mostly relevant when saving the image as a jpeg image where the more you compress the image the worse the image looks. This options is called --quality. The scaling and addtextwatermark script also has an interpolationquality option which is used with image scaling.

If the export file type is not specified then if possible the export file type will be set to that of the first imported image file. If the destination folder doesn't exist then it will be created by the script.

Add text watermark

The add text watermark script allows you to add a text watermark to image files. The script also has an option to scale the image before apply the text watermark. The script will draw the text centred in the image. If a font size is not specified then the script will calculate the font size based on attempting to make the width of the text half the image width. The script takes a stroke width option which can be a negative value. Negative values result in the text being drawn and then stroked with the stroke width. By specifying a semitransparent text black color, and a semitransparent white stroke color you still get the benefit of a watermark that doesn't overwhelm the image but is nearly alway legible no matter the color or pattern of the image the watermark is drawn on.

addtextwatermark --watermarktext "© Kevin" --outputdir ~/Desktop/textwatermarkedimages --quality 0.8 --strokewidth=-5 -f 0.1,0.1,0.1,0.25 --strokecolor 0.9,0.9,0.9,0.25 --scale 0.4 --verbose ~/Pictures/aatemp/*.JPG

The above doesn't specify the font to draw the text with, you can do that by adding the command line option --postscriptfont with a post script font name. The addtextwatermark script defaults to using the 'AvenirNext-Heavy' font because it works well with larger absolute stroke width values.

Custom crop an image

The custom crop script allows you to crop the image by different amounts from each edge of the image. If you don't specify a crop width for an edge, then the crop width takes the default value of 0. The following example crops from the bottom and top edges, copies the metadata from the original image to the cropped image, and saves the images as public.jpeg since the original images are public.jpeg images.

customcrop --top 200 --bottom 300 --outputdir ~/Desktop/DestinationImages --copymetadata ~/Desktop/SourceImages/*.jpg

Add a custom shadow

The custom add shadow script allows you to specify the shadow width for each edge of the image, top, left, bottom, right. If you don't specify a width for an edge, then the width takes the default value of 0. The shadow gradates from being partially transparent at the edge of the drawn image, to being fully transparent at the edge of the canvas. This is similar to a shadow drawn around windows on OS X. In the following example the processed images are all saved in the folder DestinationImages as png files and have the file extension .png.

customaddshadow --down 30 --right 30 --blur 20 -r 0.25 -b 0.25 -g 0.25 --verbose --outputdir ~/Desktop/DestinationImages ~/Desktop/SourceImages/*.JPG

Custom pad an image

The custom pad script allows you to pad the image by different amounts from each edge of the image. If you don't specify a pad width for an edge then the pad width takes the default value of 0. The export file format is the same as the input file format unless otherwise specified. The following example pads the image on the left and right edges with a dark blue color, and saves the images as public.jpeg since the original images are public.jpeg images.

custompad --left 200 --right 100 --red 0.1 --green 0.1 --blue 0.3 --outputdir ~/Desktop/DestinationImages --copymetadata ~/Desktop/SourceImages/*.jpg

Scale images

The scale images script has three options for scaling the image, --scale, --scalex, and --scaley. At least one needs to be specified. If you use --scale, then you shouldn't specify --scalex, and --scaley. If you don't specify --scale, then you specify --scalex or --scaley, or both. The scale image script takes two different quality options. The export quality option as described above, and a second option which is the interpolation quality. The interpolation quality option is used when the image is actually scaled. The following script scales the images by a factor of 0.5, with a medium interpolation quality. The script lists the files as they are processed, displays the configuration options and sets the export quality level to 0.8.

scaleimages --scale 0.5 --outputdir ~/Desktop/DestinationImages --verbose --quality 0.8 --interpqual medium ~/Pictures/aatemp/*.JPG

Simple single cifilter

The simplesinglecifilter script allows you to apply a single core image filter to images. The selection of filters is limited to those filters that take a single input image and up to two numerical inputs. Thus the name. That still leaves a decent list of filters you can apply including the blurring filters and the unsharp mask core image filter. To get a list of the core image filters you use can use:

simplesinglecifilter --listfilters

To find out what inputs a filter requires apart from the input image you can use:

simplesinglecifilter --filterproperties CIUnsharpMask

The numeric inputs have default values that will be used if the input is not specified on the command line. To apply the color invert filter to images:

simplesinglecifilter --filter CIColorInvert --exportfiletype public.jpeg --outputdir ~/Desktop/colorinvert --softwarerender --verbose ~/Pictures/aatemp/*.JPG

Or to apply the unsharp mask filter to images:

simplesinglecifilter --filter CIUnsharpMask --inputkey1 inputRadius --inputvalue1=10.0 --inputkey2 inputIntensity --inputvalue2=0.7 --exportfiletype public.tiff --outputdir "~/Desktop/unsharpmask" ~/Pictures/aatemp/*.JPG

Do transition

The do transition script is a bit different to the other scripts. Instead of an unknown number of input images the script takes two specific input images and outputs a series of images that is a transition from the source image to the target image. The script has a lot of optional inputs which covers all the inputs for the transition filters. To get a list of the transition filters you can use:

dotransition --listfilters

To get the properties that are specific to an individual transition filter you use the --filterproperties command line option. For example to get the filter properties relevant to copy machine transition filter:

dotransition --filterproperties CICopyMachineTransition

Unlike the simple single cifilter script the default values are not set. Every property listed using the --filterproperties option needs to have its equivalent on the command line specified. Every transition filter needs to have the source and target image specified for the filter.

The flash striation filter is a fairly complex one, requiring the specification of a color, a location as well as three numeric values. The color is specified as a series of 4 numbers between 0 and 1 each representing a color component and the alpha value. Each entry is separated by a comma without any spaces or any other character not numeric related. Specifying a location is similar, it is two numbers separated by a comma (x, y). The same goes for the extent (x, y, width, height). The command line for applying a flash transition is:

dotransition --transitionfilter CIFlashTransition --sourceimage ~/Pictures/aatemp/DSCN0744.JPG --targetimage ~/Pictures/aatemp/DSCN0744.JPG --basename flashtransition --outputdir ~/Desktop/flashtransition/ --count 40 --exportfiletype public.tiff --color 0.1,0.2,0.8,1.0 --center 450,400 --extent 0,0,2272,1704 --striationstrength 0.5 --fadethreshold 0.6 --striationcontrast 1.5

Additional Scripts you can download

These are scripts that haven't yet been updated to work with the ruby gem. Please don't judge me on these scripts, they represent my first steps with using ruby as a scripting language, I've improved a lot since writing these but I am still a novice.

Create an animation

This script will create a gif animation from the list of files provided at the specified frame delay time. The create animation script also takes an optional argument --loopcount. The following example specifies a frame delay time of 0.5 seconds, and leaves the loopcount option unspecified, which leaves it at its default value of 0, meaning that the animation repeats indefinitely.

./createanimation --delaytime 0.5 --outputfile ~/Desktop/DestinationImages/myanimation.gif --verbose ~/Desktop/SourceImages/file01.jpg ~/Desktop/SourceImages/file02.jpg ~/Desktop/SourceImages/file03.jpg ~/Desktop/SourceImages/file04.jpg ~/Desktop/SourceImages/file05.jpg

Download the create animation script

Add a shadow

The following command will process the jpeg files in the Pictures/aatemp folder with the file extension .JPG. The script will add a shadow to the image which is offset to the bottom right of the image. The color of the shadow is a medium dark grey with no transparency. If you don't specify the alpha value, a default alpha value of 1 (fully opaque) is used. The processed images are all saved in the folder DestinationImages as png files and have the file extension .png.

./addshadow --down 30 --right 30 --blur 20 -r 0.25 -b 0.25 -g 0.25 --verbose --outputdir ~/Desktop/addshadow ~/Pictures/aatemp/*.JPG

Download the add shadow script

Quartz blend

The quartz blend script allows you to combine images uses the various different quartz blend modes. The script takes a foreground and a background image. The foreground image is drawn onto the background image using the applied quartz blend graphics mode.

To get a list of blend modes.

./quartzblend --listblendmodes

To see what the effect is of drawing with the kCGBlendModeSaturation

./quartzblend --foregroundimage ~/Desktop/foregroundimage.png --backgroundimage ~/Desktop/backgroundimage.png --blendmode kCGBlendModeSaturation --outputfile ~/Desktop/blendmodesaturation.png

Download the quartz blend script

CoreImage blend mode

The core image blend mode script is similar to the quartz blend mode script. You use it to combine images uses the various core image blend modes. The script takes a foreground and a background image. The foreground image is drawn onto the background image using the applied quartz blend graphics mode.

To get a list of core image blend modes.

./coreimageblend --listfilters

To see what the effect is of drawing using CoreImage with the CIMaximumCompositing mode:

./coreimageblend --foregroundimage ~/Desktop/foregroundimage.png --backgroundimage ~/Desktop/backgroundimage.png --filter CIMaximumCompositing --outputfile ~/Desktop/blendmodemaximumcompositing.png --verbose

Download the core image blend script

Emboss Mask

The emboss mask script is really just a demonstration script for creating an image filter chain. To use the script you'll need an image like this one
Mask Image
as an input image, just black and white or grayscale and fairly simple.

./embossmask --spherediameter 400 --scale 16 --outputfile "~/Desktop/embossedbumpedlogoanimation.gif" --bumpradius 250 --radius 17 --inputfilemask ~/Desktop/exampleimages/MovingImagesMaskSmall.png

The above will create an animation of an embossed version of the mask image that wobbles in and out of the page.

Download the emboss mask script

TextWrangler Scripts

For people who don't like using the terminal I have written a few scripts which can be run from within TextWrangler. Do Command-R to run the front window as a script. The scripts are:

The "add text watermark" script allows you to add a text watermark to the center of your images and can optionally scale your images at the same time. You can specify the font, including traits like bold/heavy/italic through the postscript font name and colors including level of transparency for filling and stroking the text.

The "scale to" script specifies the width that you wish to have the images scaled to a width of.

The "transition" script allows you to generate a transition between two images made up of multiple image frames. The transition script allows you to select the core image transition filter to apply to generate the transition sequence with. If you need to specify the inputMaskImage, or inputBacksideImage filter property keys then the value for each key is a file path.

The "transition options" scripts outputs a list of the transition filters and the properties that you need to define for each transition filter. This provides information needed for the command line options for the transition script.

Contents | Introduction | JSON | Creating Objects | Playing with Objects | Drawing | Image Filter Chains | Image Metadata | Scripts | Asynchronous Commands and Performance

© Zukini Ltd. 2015