🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #15961

Re: [AS] Preflight script to scale images... geometric bounds not working

#15961
From: Olav_Kvern
Date: Fri, 24 Oct 2003 21:16
102 lines
5043 bytes
Nathan--

Try this version! I think it does most of what you want.

--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 = "GIF" 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) 
				--If the image has been scaled to something other than 100%, 
				--and if it has not already been resized in photoshop... 
				if myHoriz is not 100 and myHoriz = myVert and 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 
						--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 = "GIF" then 
							set myImageDocument to save docRef in file myFileName as CompuServe GIF 
						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 
				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 
	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

Thanks,

Ole
Technical Details
Message-ID: <2ccdf3b1.5@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx
References: <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-10-24 14:37:43 PST
From: Olav_Kvern@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.5@webx.la2eafNXanI>
Date: Fri, 24 Oct 2003 14:16:41 -0700
References: <2ccdf3b1.-1@webx.la2eafNXanI>
Lines: 108
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit