Applying Quicktime filter effects

The create composition element command which is described in the Drawing shapes documentation section can also be used to apply quicktime filter effects. The filter effects have a number of parameters that can be set to configure the effects, which iMagine provides access to.

The range of available filter effects are:

For the definition of the required and optional properties for each filter effect see the Composition Elements 2 documentation. This page is more about the examples of how to use the filter effects.

The first example demonstrates the blur filter effect with the greatest amount of blurring being applied. Panther users can open the following script in a new Script Editor window by clicking here.

on run
set thisFile to choose file with prompt "Choose an image file to apply a filter effect to: "
  
tell application "iMagine Photo"
  
set thisImporter to import graphic thisFile
if the component error of thisImporter is not equal to 0 then
close thisImporter
return
end if
set {x, y, xDim, yDim} to the natural bounds of thisImporter
if xDim is greater than 1024 or yDim is greater than 1024 then
set the scale of thisImporter to {0.5, 0.5}
set the top left point of thisImporter to {0, 0}
set xDim to xDim div 2
set yDim to yDim div 2
end if
set thisDocument to make new window document with properties {dimensions:{xDim, yDim}}
set the drawing destination of thisImporter to thisDocument
draw thisImporter
close thisImporter
set effectsRecord to {class:blur, blur amount:most}
tell thisDocument to create composition element with properties effectsRecord
end tell
end run

The second example script applies an RGB balance filter effect to the central part of the image. The red factor is increased by 50% while both the green and blue factors are reduced by 25% each. Panther users can open the following script in a new Script Editor window by clicking here.

The centre gradient filter effect darkens or lightens the edges of the bounds rectangle relative to the centre of the bounds rectangle. The bounds rectangle is the rectangle of the window or graphic document that the create composition lement command is being applied to, unless it is set as in the script above. Applying filter effects using the create composition element command, it is possible to limit the area that the filter effect applied to by defining a polygon. The polygon is bounded by lines which are defined by a list of filter clipping points. The third example demonstrates the centre gradient filter effect limited to an area defined by the filter clipping points. Panther users can open the following script in a new Script Editor window by clicking here.

The fourth script demonstrates four filter effects that have not already been demonstrated. Panther users can open the following script in a new Script Editor window by clicking here.

on run
  
set thisFile to choose file with prompt "Choose an image file to apply a filter effect to: "
  
tell application "iMagine Photo"
    
set thisImporter to import graphic thisFile
    
if the component error of thisImporter is not equal to 0 then
      
close thisImporter
      
return
      
end if
    
set {x, y, xDim, yDim} to the natural bounds of thisImporter
    
if xDim is greater than 1024 or yDim is greater than 1024 then
      
set the scale of thisImporter to {0.5, 0.5}
      
set the top left point of thisImporter to {0, 0}
      
set xDim to xDim div 2
      
set yDim to yDim div 2
    
end if
    
set thisDocument to make new window document with properties {dimensions:{xDim, yDim}}
    
set the drawing destination of thisImporter to thisDocument
    
draw thisImporter
    
close thisImporter
    
set effectsRecord1 to {class:color tint, tint type:sepia, bounds rectangle:{0, 0, xDim div 2, yDim div 2}}
    
set effectsRecord2 to {class:brightness and contrast, brightness:-20, contrast:20, bounds rectangle:{xDim div 2, 0, xDim, yDim div 2}}
    
set effectsRecord3 to {class:sharpen, amount to sharpen:most, bounds rectangle:{0, yDim div 2, xDim div 2, yDim}}
    
set effectsRecord4 to {class:emboss, amount to emboss:average, bounds rectangle:{xDim div 2, yDim div 2, xDim, yDim}}
    
tell thisDocument to create composition element with properties {effectsRecord1, effectsRecord2, effectsRecord3, effectsRecord4}
    
end tell
end run

The ability to open scripts in a new Script Editor window is provided by an application called "Convert Script to Markup Code" and can be obtained from http://homepage.mac.com/jonn8/as/

keywords: AppleScript, Apple Script, shape drawing, Macintosh, Mac, Quicktime filter effects