C
3: Scripting Photoshop
HAPTER
Manipulating a document object
The following examples demonstrate how to do the following:
➤
Save the existing ruler unit preferences, and set ruler units to inches
➤
Open an existing file as a document (using file Ducky.tif)
➤
Change the size of the image to 4 inches wide and 4 inches high.
➤
Change the size of the document window (or canvas) to 4 inches high and 4 inches wide.
➤
Trim the top and bottom of the image.
➤
Crop the image.
➤
Flip the entire window.
➤
Restore the original ruler units.
N
: See
OTE
AS
tell application "Adobe Photoshop CS4"
set saveUnit to ruler units of settings
set ruler units of settings to inch units
set duckFile to alias ¬
open duckFile
set docRef to current document
resize image docRef width 4 height 4
resize canvas docRef width 4 height 4
trim docRef basing trim on top left pixel with top trim ¬
set ruler units of settings to pixel units
crop current document bounds {100, 200, 400, 500} angle 45 width 20 height 20
flip canvas docRef direction horizontal
set ruler units of settings to saveUnit
end tell
VBS
Dim appRef, docRef
Set appRef = CreateObject("Photoshop.Application")
'save original ruler units, then set ruler units to inches
startRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = 2 'for PsUnits --> 2 (psInches)
Set docRef = appRef.Open(appRef.Path & "\Samples\Ducky.tif")
docRef.ResizeImage 4,4
docRef.ResizeCanvas 4,4
'Trim the document with
' type = 1 (psTopLeftPixel)
' top=true, left=false, bottom=true, right=false
docRef.Trim 1,True,False,True,False
'the crop command uses unit values
'so change the ruler units to pixels
appRef.Preferences.RulerUnits = 1 ' (psPixels)
"Setting Application Preferences" on page 32
"OS X 10.4.8 US:Applications:Adobe Photoshop CS4:Samples:Ducky.tif"
and bottom trim without left trim and right trim
Working with the Photoshop Object Model 35
for information on ruler units.