Here's the AppleScript I wrote:
Code: Select all
on watermark(water_mark_file, orig_image, wm_corner)
set copyrightText to "© 2015"
set artistText to "Me, myself, and I"
set new_filename to item 2 of parse_file(orig_image) & "." & item 3 of parse_file(orig_image)
--display dialog new_filename
set filepath to item 1 of parse_file(orig_image)
set amount_to_blend to 15 as integer -- (% transparency)
tell application "iMagine Photo.app"
-- Import image and watermark and create a window to draw them to.
set waterMarkImporter to «event ASDsimGr» water_mark_file
if the «class imEr» of waterMarkImporter is not equal to 0 then
close waterMarkImporter
return
end if
set thisImporter to «event ASDsimGr» orig_image
(* Set copyright info *)
set theProps to the «class iPdt» of thisImporter
copy the «class GrTy» of theProps to graphicType
tell thisImporter to «event ASDsmaEx» given «class prdt»:{«class exFT»:"JPEG"}
set the «class eFlc» of thisImporter to orig_image
set the «class eExD» of thisImporter to {{«class udTy»:«constant udTy©cpy», «class exUn»:copyrightText}, {«class udTy»:«constant udTy©ART», «class exUn»:artistText}}
if the «class imEr» of thisImporter is not equal to 0 then
close waterMarkImporter
return
end if
set {x, y, xDim, yDim} to the «class NBRe» of thisImporter
set thisDocument to make new «class WiDo» with properties {«class gWSz»:{xDim, yDim}}
set the «class grDc» of thisImporter to thisDocument
set the «class grDc» of waterMarkImporter to thisDocument
«event ASDsdraw» thisImporter
(*
Scaling and positioning code for the watermark.
The height of the watermark will be no taller than 1/3 the height of the image.
*)
set {x, y, xWDim, yWDim} to the «class NBRe» of waterMarkImporter
if xDim > yDim then
set one_third to xDim / 3
if xWDim ≤ one_third then
set scaleX to 1
else
set scaleX to one_third / xWDim
end if
set scaleY to scaleX
else
set one_third to yDim / 3
if yWDim ≤ one_third then
set scaleY to 1
else
set scaleY to one_third / yWDim
end if
set scaleX to scaleY
end if
(* Since the watermark is now smaller, use the new size in setting the position. *)
set new_xWDim to xWDim * scaleX
set new_yWDim to yWDim * scaleY
if wm_corner is equal to "Top Left" then
set theTop to 10
set theLeft to 10
else if wm_corner is equal to "Center Left" then
set theTop to ((yDim - new_yWDim) / 2) as integer
set theLeft to 10
else if wm_corner is equal to "Bottom Left" then
set theTop to yDim - new_yWDim - 10
set theLeft to 10
else if wm_corner is equal to "Top Middle" then
set theTop to 10
set theLeft to ((xDim - new_xWDim) / 2) as integer
else if wm_corner is equal to "Center Middle" then
set theTop to ((yDim - new_yWDim) / 2) as integer
set theLeft to ((xDim - new_xWDim) / 2) as integer
else if wm_corner is equal to "Bottom Middle" then
set theTop to yDim - new_yWDim - 10
set theLeft to ((xDim - new_xWDim) / 2) as integer
else if wm_corner is equal to "Top Right" then
set theTop to 10
set theLeft to xDim - new_xWDim - 10
else if wm_corner is equal to "Center Right" then
set theTop to ((yDim - new_yWDim) / 2) as integer
set theLeft to xDim - new_xWDim - 10
else if wm_corner is equal to "Bottom Right" then
set theTop to yDim - new_yWDim - 10
set theLeft to xDim - new_xWDim - 10
end if
set the «class Scal» of waterMarkImporter to {scaleX, scaleY}
set the «class TLPt» of waterMarkImporter to {theLeft, theTop}
set amount_to_blend to (amount_to_blend / 100) * 65535 as integer
set blendOpColor to {amount_to_blend, amount_to_blend, amount_to_blend}
set the «class drMd» of waterMarkImporter to {«class grMd»:«constant grMd », «class opCo»:blendOpColor}
«event ASDsdraw» waterMarkImporter
set «class eFlc» of thisDocument to filepath & ":" & new_filename
set wm_image to filepath & ":" & new_filename
«event ASDsxprt» thisDocument
close thisDocument
close thisImporter
close waterMarkImporter
quit
end tell
return wm_image
end watermark