Detailed documentation
Watermarking image files and setting copyright information
How you do watermarking depends on whether your logo or image that you want to use for watermarking has an alpha channel (Transperancy) or not. If you wish to add an alpha channel using iMagine Photo to your watermark then you can see how to do this on the transparency page.
In the following examples I will be scaling the watermark to fill as much of the image as possible without stretching or allowing the watermark to extend beyond the edges of the image.
The following script blends a watermark with your image file and creates a new image with the watermark applied. In Panther to open the script in a new Script Editor window click here.
on run
set waterMarkFile to choose file with prompt "Choose your watermark image: "
set thisImage to choose file with prompt "Choose your image file: "
set finalFile to choose file name "Watermarked image file: " default name "Watermarked Image.jpg"
set amountToBlend to GetInteger("Enter the amount to blend as Percentage: ", 10, 0, 100)
if gotnum of amountToBlend is false then
return
end if
set amountToBlend to returnedresult of amountToBlend
tell application "iMagine Photo"
-- import image and watermark and create a window to draw them to.
set waterMarkImporter to import graphic waterMarkFile
if the component error of waterMarkImporter is not equal to 0 then
close waterMarkImporter
return
end if
set thisImporter to import graphic thisImage
if the component error of thisImporter is not equal to 0 then
close waterMarkImporter
return
end if
set {x, y, xDim, yDim} to the natural bounds of thisImporter
set thisDocument to make new window document with properties {dimensions:{xDim, yDim}}
set the drawing destination of thisImporter to thisDocument
set the drawing destination of waterMarkImporter to thisDocument
draw thisImporter
-- scaling and positioning code for the watermark
set {x, y, xWDim, yWDim} to the natural bounds of waterMarkImporter
set scaleX to xDim / xWDim
set scaleY to yDim / yWDim
set theTop to 0
set theLeft to 0
if scaleY is less than scaleX then
set scaleX to scaleY
set theLeft to ((xDim - (scaleX * xWDim)) / 2) as integer
else
set scaleY to scaleX
set theTop to ((yDim - (scaleY * yWDim)) / 2) as integer
end if
set the scale of waterMarkImporter to {scaleX, scaleY}
set the top left point of waterMarkImporter to {theLeft, theTop}
set amountToBlend to (amountToBlend / 100) * 65535 as integer
set blendOpColor to {amountToBlend, amountToBlend, amountToBlend}
set the drawing mode of waterMarkImporter to {graphics mode:blend, opcolor:blendOpColor}
draw waterMarkImporter
set export file location of thisDocument to finalFile
export thisDocument
close thisDocument
close thisImporter
close waterMarkImporter
end tell
end run
on GetInteger(theString, theDefault, min, max)
repeat
set theResult to display dialog theString default answer theDefault
if the button returned of theResult is "Cancel" then
return {gotnum:false}
end if
try
set theValue to the (text returned of theResult) as integer
if (theValue is greater than min) and (theValue is less than max) then
return {gotnum:true, returnedresult:theValue}
end if
end try
end repeat
end GetInteger
The simplest variation on the above script is the ability to take advantage of the alpha channel. Note that not all image formats support alpha channel functionality, the most commonly used format is PNG because PNG files can be viewed by most web browsers. To modify the above script for blending a watermark with an alpha channel all you have to do is to replace the following line in the script above:
set the drawing mode of waterMarkImporter to {graphics mode:blend, opcolor:blendOpColor}
with this line:
set the drawing mode of waterMarkImporter to {graphics mode:alpha blend, opcolor:blendOpColor}
If the alpha channel contains all the blending/transparency information that you need then remove all the lines in the above script which have amountToBlend in them and replace the drawing mode line as in the previous change with
set the graphics mode of waterMarkImporter to straight alpha
It is not necessary that the watermark covers as much of the original picture as possible, it is only that I have designed the scripts above to do that.
The following script sets the exif copyright and artist information in the image. The script replaces the contents of the original file. To find out more about reading and writing exif information and other properties of image files see the Read/Write Exif metadata page. In Panther to open the script in a new Script Editor window click here.
tell application "iMagine Photo"
set thisFile to choose file with prompt "Image file to set copyright information to: "
set copyrightText to text returned of (display dialog "Enter the copyright text: " default answer "Copyright me, myself, and I, http://www.yvs.eu.com, Oxford UK 2004")
set artistText to text returned of (display dialog "Photographers name: " default answer "Kevin Meaney")
set thisImporter to import graphic thisFile
tell thisImporter to make exporter with properties {export file type:"JPEG"}
set the export file location of thisImporter to thisFile
set the export exif data of thisImporter to {{exif type:copyright, exif unicode:copyrightText}, {exif type:artist, exif unicode:artistText}}
export thisImporter
close thisImporter
end tell
Script 1 is a droplet that applies the watermark and sets the copyright and artist information to the image files dropped on the script. The script replaces the contents of the original files. The script is configured by running it (double clicking) and you will be provided with options for the blending and/or using the alpha channel of the watermark, choosing the image to be used as the watermark and setting the copyright information.
The page Preparing for the internet includes scripts that combine applying watermarks and the copyright information as well as other actions relevant to preparing files for the internet. The script is called AllSingingAllDancingDroplet because it performs all the relevant operations related to preparing image files for the internet.
The ability to open scripts in a new Script Editor window is provided by a little script called "Convert Script to Markup Code" and can be obtained from http://homepage.mac.com/jonn8/as/
keywords: AppleScript, Apple Script, jpeg, jpg, image, graphic, Macintosh, watermarking, copyright, exif.
