Article View: adobe.scripting.indesign
Article #15790Re: [AS] Preflight script to scale images... geometric bounds not working
From: Kari_Puikkonen
Date: Sun, 16 Nov 2003 18:09
Date: Sun, 16 Nov 2003 18:09
126 lines
5619 bytes
5619 bytes
Nathan,
Ole's scripts works only if you have scaled your images with Transform palette.
I modified the script so that it works with images that have been scaled with selection tool.
--ResampleImages.as
--Resamples all images in the active document (using Photoshop)
--to their scaled size; sets the scaling on all frames to 100%.
set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "InDesign 2.0.2"
set myDocument to active document
tell myDocument
set outdateLinks to every link whose status is link out of date
repeat with OODLinks from (count outdateLinks) to 1 by -1
update link of item OODLinks of outdateLinks
end repeat
set IDLinks to every link whose status is normal
--Iterate backwards through the links to avoid invalidating objects.
repeat with myCounter from (count IDLinks) to 1 by -1
set myLink to item myCounter of IDLinks
--Process only image links.
set myLinkType to link type of myLink
--If statement could be expanded to include other image types.
if myLinkType = "TIFF" or myLinkType = "JPEG" or myLinkType = "Photoshop" then
set LinkName to name of myLink
set theImage to parent of myLink
set theFrame to parent of theImage
--get the path
set ImagePath to file path of item myCounter of IDLinks as string
--get the image's location
set ImgPos to geometric bounds of theImage
set FramePos to geometric bounds of theFrame
--get the scale
set myHoriz to horizontal scale of theImage as real
set myVert to vertical scale of theImage as real
--get the bounds of the image
set myY1 to (item 1 of ImgPos)
set myX1 to (item 2 of ImgPos)
set myY2 to (item 3 of ImgPos)
set myX2 to (item 4 of ImgPos)
--I modified this line
if ImagePath is not in myProcessedLinks then
set myFileName to my myMakeFileName(myFolder, ImagePath as alias, myHoriz)
--...then scale the graphic in Photoshop:
tell application "Adobe Photoshop 7.0"
activate
open file ImagePath
set docRef to current document
resize image docRef width myHoriz as percent resample method none
--I added this line to also resample the images
resize image docRef resolution 300 resample method bicubic
--If...else if statement could be expanded to handle other file types.
if myLinkType = "TIFF" then
set myImageDocument to save docRef in file myNewFileName as TIFF
else if myLinkType = "JPEG" then
set myImageDocument to save docRef in file myFileName as JPEG
else if myLinkType = "Photoshop" then
set myImageDocument to save docRef in file myFileName as Photoshop format
end if
set myFileName to file path of myImageDocument
close current document saving no
--close docRef with saving
end tell
relink myLink to myFileName
--When you update the link, the old link is destroyed
--and InDesign returns the new link.
set myLink to update myLink
set theImage to parent of myLink
set theFrame to parent of theImage
set properties of theFrame to {horizontal scale:100, vertical scale:100, geometric bounds:FramePos}
set properties of theImage to {horizontal scale:100, vertical scale:100, geometric bounds:ImgPos}
copy myFileName to end of myProcessedLinks
--I had to add this, because otherwise imeges end up distorted.
fit theFrame given proportionally
else if ImagePath is in myProcessedLinks then
set myLink to update myLink
end if
end if
end repeat
end tell
end tell
on myMakeFileName(myFolder, myFile, myHoriz)
set myFileInfo to info for myFile
set myFileName to name of myFileInfo
set myFolderName to myFolder as string
--I had to change dots to commas. Otherwise Photoshop gives me an error (but I don't know why...).
if (myHoriz as string) contains "," then
set myOldDelimiters to text item delimiters
set text item delimiters to ","
set myHoriz to text item 1 of (myHoriz as string)
set text item delimiters to myOldDelimiters
end if
if myFileName contains "," then
set myOldDelimiters to text item delimiters
set text item delimiters to ","
set myFileName to text item 1 of myFileName
set text item delimiters to myOldDelimiters
end if
set myNewFileName to myFileName & "_" & (myHoriz as string)
set myNewFilePath to myFolderName & myNewFileName
return myNewFilePath
end myMakeFileName
Ole,
A couple of questions.
1.) The resulting images (not the frames) are 99.something%. Why and how do I fix that?
2.) Would this script work as is with CS? (I'm receiveng my copy next week, so I can't test this ; ))
Kari
Technical Details
Message-ID:
<2ccdf3b1.8@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<2ccdf3b1.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,bcc0c6dca106f772 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-11-16 10:37:44 PST From: Kari_Puikkonen@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: Re: [AS] Preflight script to scale images... geometric bounds not working Message-ID: <2ccdf3b1.8@webx.la2eafNXanI> Date: Sun, 16 Nov 2003 10:09:14 -0800 References: <2ccdf3b1.-1@webx.la2eafNXanI> Lines: 134 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit