Article View: adobe.scripting.indesign
Article #20066Re: Photo resizing scipt
From: rob day
Date: Wed, 06 Nov 2002 13:03
Date: Wed, 06 Nov 2002 13:03
147 lines
7082 bytes
7082 bytes
Peter,
I wrote this for my own use, so you will have to adapt it. My workflow is to make raw scans at the scanners optical res and place them as JPEG. This script opens every JPEG in the layout, puts it into a layered PS file at 300ppi with the dimensions of the frame, rotates, scales, offsets, and runs a desired action. The layered file is saved with the page number as a prefix into one folder and a lo res 72ppi EPS version with the same name to another (you'll have to set the paths). I haven't made much effort to trap errors and I'm sure it could be streamlined:
tell application "InDesign 2.0.1"
--the path to the folder for the 300ppi layered Photoshop Format files and a folder for a 72ppi version with the same name
set thePath to "KESTRAL:ROB ONGOING BIG:BATCH LAYERED:"
set loPath to "KESTRAL:ROB ONGOING BIG:BATCH LAYERED:LO RES:"
set myDoc to active document
tell myDoc
tell view preferences
set myOrigHorMeasurementUnits to get horizontal measurement units
set myOrigVerMeasurementUnits to get vertical measurement units
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
end tell
repeat with docLinks from 1 to (count links of active document)
set myLink to link docLinks of active document
--gets the page number for name if needed
set pageId to parent of parent of parent of myLink
set pageNo to name of pageId
--setting the fileName to name of myLink keeps the same name as the placed file.
--Maybe this is good --don't need to relink, but could the page number be inseted?
set fileName to name of myLink
--Use this to put page number in front of name. If you want to maintain the same name remove "0" & pageNo & "-" &
set newName to "0" & pageNo & "-" & fileName
--set this to only JPEG and always have the FPO be JPEG and things like logos be EPS or TIFF which are hi res and get skipped.
--If you want everything opened use:
--if link type of myLink is "EPS" or link type of myLink is "JPEG" or link type of myLink is "TIFF" then
if link type of myLink is "JPEG" then
set myFileName to file path of myLink
--the picture box could be parent of myLink
set myFrame to parent of parent of myLink
set myPic to parent of myLink
--gets the pictures scale
set myVScale to absolute vertical scale of myPic
set myHScale to absolute horizontal scale of myPic
--gets the pictures rotation
set myRotation to absolute rotation angle of myPic
--gets the bounding box of both the picture and the picture box
set boxBounds to geometric bounds of myFrame
set picBounds to geometric bounds of myPic
--gets the dimension for the PS file
set boxRight to item 4 of boxBounds
set boxleft to item 2 of boxBounds
set boxTop to item 1 of boxBounds
set boxBottom to item 3 of boxBounds
set boxHeight to boxBottom - boxTop
set boxWidth to boxRight - boxleft
--for the picture offset relative to the frame
--picture center of bounds
set picX1 to item 2 of picBounds
set picY1 to item 1 of picBounds
set picX2 to item 4 of picBounds
set picY2 to item 3 of picBounds
set picXCenter to picX1 + ((picX2 - picX1) / 2)
set picYCenter to picY1 + ((picY2 - picY1) / 2)
--frame center of bounds
set boxX1 to item 2 of boxBounds
set boxY1 to item 1 of boxBounds
set boxX2 to item 4 of boxBounds
set boxY2 to item 3 of boxBounds
set boxXCenter to boxX1 + ((boxX2 - boxX1) / 2)
set boxYCenter to boxY1 + ((boxY2 - boxY1) / 2)
--offset of picture to frame
set hOff to picXCenter - boxXCenter
set vOff to picYCenter - boxYCenter
tell application "Adobe Photoshop 7.0"
activate
--For the lo res eps, can be adjusted to TIFF. Look in Save Formats Suite for this
set myOptions to �
{class:EPS save options, embed color profile:false, preview type:none, encoding:binary, halftone screen:false, image interpolation:false, PostScript color management:false, transfer function:false}
try
open myFileName
on error
display dialog " Update Indesign Links"
return
end try
--apply gathered variables to images here
tell current document
resize image width percent myHScale resample method none
resize image resolution 300 resample method bicubic
--couldn't figure out how to make the default background layer a normal layer
--don't want the picture to get clipped by the canvas reize.
select all
copy
paste
set name of layer "Layer 1" to "Photo"
delete layer "Background"
resize canvas width boxWidth height boxHeight
rotate layer "Photo" angle -myRotation
end tell
tell layer "Photo" of current document
translate delta x hOff
translate delta y vOff
--can apply any desired actions here:
--try
--do action "DUOTONE NEUTRAL" from "PINGREE"
--on error
--display dialog "Open Pingree Action Set and Try Again."
tell application "Adobe Photoshop 7.0"
tell current document
close saving no
end tell
end tell
return
--end try
end tell
tell application "Adobe Photoshop 7.0"
save current document in file (thePath & newName) as Photoshop format appending no extension with replacing
--makes a lo res version to the loPath folder. Comment this out if you don't want a lo res version.
tell current document
flatten
resize image resolution 72 resample method bicubic
change mode to RGB
tell application "Adobe Photoshop 7.0"
save current document in file (loPath & newName) �
as Photoshop EPS with options myOptions appending no extension with replacing
end tell
end tell
tell current document
close saving no
end tell
end tell
end tell
end if
end repeat
tell myDoc
tell view preferences
set horizontal measurement units to myOrigHorMeasurementUnits
set vertical measurement units to myOrigVerMeasurementUnits
end tell
end tell
end tell
Technical Details
Message-ID:
<1de66c77.1@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<1de66c77.-1@WebX.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f939a,ba51c749711790d8 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-11-06 05:31:44 PST From: "rob day" <vevans@mediaone.net> Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Photo resizing scipt Message-ID: <1de66c77.1@WebX.la2eafNXanI> Date: Wed, 6 Nov 2002 05:03:09 -0800 References: <1de66c77.-1@WebX.la2eafNXanI> Lines: 167 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit