Photoshop Resizing of Images Placed in InDesign Script

I downloaded this code from some site (not sure?) and was wondering why it seems to only work on RGB files. For layouts we usually use CMYK color space and would like to have this work on all file types. Another helpful item would be for it to identify EPS files created in Illustrator (vector based files) and ignore them. We don’t want those resized in Photoshop CS. Any ideas would be most appreciated.
–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 CS”
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 = “EPS” or myLinkType = “Photoshop format” or myLinkType = “PDF” 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 CS”
–activate
open file ImagePath
set docRef to current document
resize image docRef width percent (myHoriz / 100) resample method bicubic sharper
–If…else if statement could be expanded to handle other file types.
if myLinkType = “TIFF” then
set myImageDocument to save docRef in file myFileName as TIFF
else if myLinkType = “EPS” then
set myImageDocument to save docRef in file myFileName as EPS
else if myLinkType = “Photoshop format” then
set myImageDocument to save docRef in file myFileName as Photoshop format
else if myLinkType = “PDF” then
set myImageDocument to save docRef in file myFileName as PDF
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

I’ve just reposted a copy of that code in the Adobe U2U forum. It works for CMYK images also, but only works for PSD and Tiff images. I haven’t figured out a way to isolate EPS from PS vs EPS from AI yet.


--ResampleImages19.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 CS"
	
	--If transformation preferences are not set to transformations are totals 
	--we have to set them for the script to work.
	if transformations are totals of transform preferences is false then
		set myOldTransPreferences to properties of transform preferences
		set transformations are totals of transform preferences to true
		set show content offset of transform preferences to true
		set dimensions include stroke weight of transform preferences to true
		set transform content of transform preferences to true
		set myResetTransform to true
	else
		set myResetTransform to false
	end if
	set myDocument to active document
	tell myDocument
		--If the measurement units of the active document are not inches, set the  
		--measurement units to inches. Units MUST be inches in order to script work. 
		if horizontal measurement units of view preferences of myDocument is not points or ¬
			vertical measurement units of view preferences of myDocument is not points then
			set myOldViewPreferences to properties of view preferences of myDocument
			set horizontal measurement units of view preferences of myDocument to points
			set vertical measurement units of view preferences of myDocument to points
			set myResetUnits to true
		else
			set myResetUnits to false
		end if
		
		
		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 = "Photoshop format" then
				set LinkName to name of myLink
				set theImage to parent of myLink
				set theFrame to parent of theImage
				-- resets the graphic frame to 100 
				reset scaling of theFrame
				--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 absolute horizontal scale of theImage
				if myHoriz is less than 0 then
					set myImageFlipHoriz to -100
				else
					set myImageFlipHoriz to 100
				end if
				
				set myVert to absolute vertical scale of theImage
				if myVert is less than 0 then
					set myImageFlipVert to -100
				else
					set myImageFlipVert to 100
				end if
				
				-- Check if frame as been flipped
				if the absolute horizontal scale of theFrame is -100 then
					set myHorizFrameHeight to 100
					set myFrameFlipHoriz to -100
				else
					set myHorizFrameHeight to (absolute horizontal scale of theFrame)
					set myFrameFlipHoriz to 100
				end if
				
				if the absolute vertical scale of theFrame is -100 then
					set myVertFrameWidth to 100
					set myframeFlipVert to -100
				else
					set myVertFrameWidth to (absolute vertical scale of theFrame)
					set myframeFlipVert to 100
				end if
				
				if (myImageFlipHoriz + myFrameFlipHoriz) is 0 then
					set myFinalHorizFlip to -100
				else
					set myFinalHorizFlip to 100
				end if
				
				if (myImageFlipVert + myframeFlipVert) is 0 then
					set myFinalHorizVert to -100
				else
					set myFinalHorizVert to 100
				end if
				
				--get the rotation and Shear of the frame 
				set FrameRot to rotation angle of theFrame
				set FrameShear to shear angle of theFrame
				
				--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 myHorizFrameHeight is 100 and myHorizFrameHeight = myVertFrameWidth 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 CS"
						--activate 
						set ruler units of settings to point units
						open file ImagePath showing dialogs never
						set docRef to current document
						resize image docRef width percent (myHoriz / 100) resample method none
						resize image docRef resolution 300 resample method bicubic sharper
						--If...else if statement could be expanded to handle other file types. 
						if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "Photoshop format" 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, rotation angle:FrameRot, shear angle:FrameShear}
					set properties of theImage to {horizontal scale:myFinalHorizFlip, vertical scale:myFinalHorizVert, geometric bounds:ImgPos}
					resize theImage horizontal scale 100 vertical scale 100 around center anchor without considering current scale and considering parents scale
					copy myFileName to end of myProcessedLinks
				else if ImagePath is in myProcessedLinks then
					set myLink to update myLink
				end if
			end if
		end repeat
		--Resets the units  
		if myResetUnits is true then
			tell view preferences of myDocument to set properties to myOldViewPreferences
		end if
	end tell
	if myResetTransform is true then
		tell transform preferences to set properties to myOldTransPreferences
	end if
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
tell application "InDesign CS"
	activate
	beep
	display dialog "Done!"
end tell

Great script! Very informative as a starting place for InDesign scripts.

How about this to isolate Photoshop EPS from AI EPS:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Put this at the top of the first repeat, replacing existing code… . Of course this will error with raster EPS files created by applications other than Photoshop.

Tom

Thanks Tom!

I got your code in the script and had to fix some little details for it to work but its great!

The only thing is that the EPS preview is in 1bit. I have to figure out a way to save the Photoshop EPS with a color preview, be it jpeg or 8 bit mac.

btw, this code is not mine, at least the most part is from Kari, and JC, me and a bunch of other people are contributing to it.
Thanks to everyone working on this. I’ll keep you posted on further version as I add stuff to it.

Lesta

Ok, forget that, I found how to fix the eps preview problem:-)

Lesta

I copied the script and made the suggested edits to include EPS files in the mix and it starts to work and then after loading the image and resizing in photoshop the script stops on an error that “the variable MyImageDocument is not defined”. What’s missing?

krdzine1,

There was another couple of lines to add a bit further in the script to handle the eps and it’s options in photoshop.

The script is in the Adobe U2U forum in ID scripting btw.

Lesta

where? I thought I copied into where you stated… can you post a complete reworked script? Thanks.

OK, here’s the latest version.


--ResampleImages20.as 
--Resamples all images in the active document (using Photoshop) 
--to their scaled size; sets the scaling on all frames to 100%. 
--version updated to work on tiff, psd and eps from Photoshop
set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "InDesign CS"
	
	--If transformation preferences are not set to transformations are totals 
	--we have to set them for the script to work.
	if transformations are totals of transform preferences is false then
		set myOldTransPreferences to properties of transform preferences
		set transformations are totals of transform preferences to true
		set show content offset of transform preferences to true
		set dimensions include stroke weight of transform preferences to true
		set transform content of transform preferences to true
		set myResetTransform to true
	else
		set myResetTransform to false
	end if
	set myDocument to active document
	tell myDocument
		--If the measurement units of the active document are not inches, set the  
		--measurement units to inches. Units MUST be inches in order to script work. 
		if horizontal measurement units of view preferences of myDocument is not points or ¬
			vertical measurement units of view preferences of myDocument is not points then
			set myOldViewPreferences to properties of view preferences of myDocument
			set horizontal measurement units of view preferences of myDocument to points
			set vertical measurement units of view preferences of myDocument to points
			set myResetUnits to true
		else
			set myResetUnits to false
		end if
		
		
		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 myLinkedFile to file path of myLink as alias
			set myLinkType to link type of myLink
			tell application "Finder" to set fileCreator to file creator of (info for myLinkedFile)
			--If statement expanded to isolate PS EPS from AI EPS. 
			if (myLinkType = "TIFF") or (myLinkType = "Photoshop") or ((myLinkType = "EPS") and (fileCreator = "8BIM")) then
				set LinkName to name of myLink
				set theImage to parent of myLink
				set theFrame to parent of theImage
				-- resets the graphic frame to 100 
				reset scaling of theFrame
				--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 absolute horizontal scale of theImage
				if myHoriz is less than 0 then
					set myImageFlipHoriz to -100
				else
					set myImageFlipHoriz to 100
				end if
				
				set myVert to absolute vertical scale of theImage
				if myVert is less than 0 then
					set myImageFlipVert to -100
				else
					set myImageFlipVert to 100
				end if
				
				-- Check if frame as been flipped
				if the absolute horizontal scale of theFrame is -100 then
					set myHorizFrameHeight to 100
					set myFrameFlipHoriz to -100
				else
					set myHorizFrameHeight to (absolute horizontal scale of theFrame)
					set myFrameFlipHoriz to 100
				end if
				
				if the absolute vertical scale of theFrame is -100 then
					set myVertFrameWidth to 100
					set myframeFlipVert to -100
				else
					set myVertFrameWidth to (absolute vertical scale of theFrame)
					set myframeFlipVert to 100
				end if
				
				if (myImageFlipHoriz + myFrameFlipHoriz) is 0 then
					set myFinalHorizFlip to -100
				else
					set myFinalHorizFlip to 100
				end if
				
				if (myImageFlipVert + myframeFlipVert) is 0 then
					set myFinalHorizVert to -100
				else
					set myFinalHorizVert to 100
				end if
				
				--get the rotation and Shear of the frame 
				set FrameRot to rotation angle of theFrame
				set FrameShear to shear angle of theFrame
				
				--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 myHorizFrameHeight is 100 and myHorizFrameHeight = myVertFrameWidth 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 CS"
						--activate 
						set ruler units of settings to point units
						open file ImagePath showing dialogs never
						set docRef to current document
						resize image docRef width percent (myHoriz / 100) resample method none
						resize image docRef resolution 300 resample method bicubic sharper
						--If...else if statement could be expanded to handle other file types. 
						if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "Photoshop format" then
							set myImageDocument to save docRef in file myFileName as Photoshop format
						else if myLinkType = "EPS" then
							set myImageDocument to save docRef in file myFileName as Photoshop EPS with options {class:EPS save options, encoding:binary, preview type:JPEG Mac OS}
						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, rotation angle:FrameRot, shear angle:FrameShear}
					set properties of theImage to {horizontal scale:myFinalHorizFlip, vertical scale:myFinalHorizVert, geometric bounds:ImgPos}
					resize theImage horizontal scale 100 vertical scale 100 around center anchor without considering current scale and considering parents scale
					copy myFileName to end of myProcessedLinks
				else if ImagePath is in myProcessedLinks then
					set myLink to update myLink
				end if
			end if
		end repeat
		--Resets the units  
		if myResetUnits is true then
			tell view preferences of myDocument to set properties to myOldViewPreferences
		end if
	end tell
	if myResetTransform is true then
		tell transform preferences to set properties to myOldTransPreferences
	end if
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
tell application "InDesign CS"
	activate
	beep
	display dialog "Done!"
end tell

Has anyone taken this to the next step and figured out a way to crop the images to the size and position of the indesign box? Preferrably with some kind of bleed area say .25 inch all around as a safety area.

Kari, the originator of the basis for this script had made this feature in the script, but I removed it because it wasn’t behaving correctly and I didn’t want it at the time. I’m sure if you check the U2U forum on Adobe Site that you’ll find the original script and fix it to do what you want, but be warned that it doesn’t work correctly.

Lesta

I am a complete dummie in AppleScript. My problem with this script is, that it cannot process non-proportional scaled images. They are lead back to their origin proportion of width and height. Is there somebody with an idea how to integrate this function? Would be great :slight_smile:

I found a solution. I replaced

set docRef to current document
                       resize image docRef width percent (myHoriz / 100) resample method none
                       resize image docRef resolution 300 resample method bicubic sharper

with

set docRef to current document
resize image docRef width percent (myHoriz / 100) height percent (myVert / 100) resolution 300 resample method bicubic sharper

But now I get a Photoshop error, which says, that Photoshop is not able to read a file "26023_175,18970950882.tif. But the document to resample does not at all contain such a file.

Again me.

I think I found the reason for this error. The script could not process .PSD files.

if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "Photoshop format" then
							set myImageDocument to save docRef in file myFileName as Photoshop format
						else if myLinkType = "EPS" then
							set myImageDocument to save docRef in file myFileName as Photoshop EPS with options {class:EPS save options, encoding:binary, preview type:JPEG Mac OS}
						end if

I changed “Photoshop format” to “Photoshop”. Now .PSD files a resampled as well.
:mad:
But there is a new issue: The script does not differentiate between halftone and bitmap TIFFs. And of course I do not want the bitmaps with a resolution of 300 dpi.

I really hope that somebody strays in this thread, because I really do not have any idea how to solve this.

Robert,

Here is my latest version of the script, it doesn’t adress some of the issues you have, and doesn’t work with CS2 yet.


--ResampleImages22.as 
--Resamples all images in the active document (using Photoshop) 
--to their scaled size; sets the scaling on all frames to 100%. 
--version updated to work on tiff, psd and eps from Photoshop
set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "InDesign CS"
	
	--If transformation preferences are not set to transformations are totals 
	--we have to set them for the script to work.
	if transformations are totals of transform preferences is false then
		set myOldTransPreferences to properties of transform preferences
		set transformations are totals of transform preferences to true
		set show content offset of transform preferences to true
		set dimensions include stroke weight of transform preferences to true
		set transform content of transform preferences to true
		set myResetTransform to true
	else
		set myResetTransform to false
	end if
	set mydocument to active document
	tell mydocument
		--If the measurement units of the active document are not inches, set the  
		--measurement units to inches. Units MUST be inches in order to script work. 
		if horizontal measurement units of view preferences of mydocument is not points or ¬
			vertical measurement units of view preferences of mydocument is not points then
			set myOldViewPreferences to properties of view preferences of mydocument
			set horizontal measurement units of view preferences of mydocument to points
			set vertical measurement units of view preferences of mydocument to points
			set myResetUnits to true
		else
			set myResetUnits to false
		end if
		
		
		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 myLinkedFile to file path of myLink as alias
			set myLinkType to link type of myLink
			tell application "Finder" to set fileCreator to file creator of (info for myLinkedFile)
			--If statement expanded to isolate PS EPS from AI EPS. 
			if (myLinkType = "TIFF") or (myLinkType = "Photoshop") or ((myLinkType = "EPS") and (fileCreator = "8BIM")) then
				set LinkName to name of myLink
				set theImage to parent of myLink
				set theFrame to parent of theImage
				-- resets the graphic frame to 100 
				reset scaling of theFrame
				--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 absolute horizontal scale of theImage
				if myHoriz is less than 0 then
					set myImageFlipHoriz to -100
				else
					set myImageFlipHoriz to 100
				end if
				
				set myVert to absolute vertical scale of theImage
				if myVert is less than 0 then
					set myImageFlipVert to -100
				else
					set myImageFlipVert to 100
				end if
				
				-- Check if frame as been flipped
				if the absolute horizontal scale of theFrame is -100 then
					set myHorizFrameHeight to 100
					set myFrameFlipHoriz to -100
				else
					set myHorizFrameHeight to (absolute horizontal scale of theFrame)
					set myFrameFlipHoriz to 100
				end if
				
				if the absolute vertical scale of theFrame is -100 then
					set myVertFrameWidth to 100
					set myframeFlipVert to -100
				else
					set myVertFrameWidth to (absolute vertical scale of theFrame)
					set myframeFlipVert to 100
				end if
				
				if (myImageFlipHoriz + myFrameFlipHoriz) is 0 then
					set myFinalHorizFlip to -100
				else
					set myFinalHorizFlip to 100
				end if
				
				if (myImageFlipVert + myframeFlipVert) is 0 then
					set myFinalHorizVert to -100
				else
					set myFinalHorizVert to 100
				end if
				
				--get the rotation and Shear of the frame 
				set FrameRot to rotation angle of theFrame
				set FrameShear to shear angle of theFrame
				
				--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 myHorizFrameHeight is 100 and myHorizFrameHeight = myVertFrameWidth and ImagePath is not in myProcessedLinks and myHoriz is not 100 then
					set myFileName to my myMakeFileName(myFolder, ImagePath as alias, myHoriz)
					
					--...then scale the graphic in Photoshop: 
					tell application "Adobe Photoshop CS"
						--activate 
						set ruler units of settings to point units
						open file ImagePath showing dialogs never
						set docRef to current document
						resize image docRef width percent (myHoriz / 100) resample method none
						resize image docRef resolution 300 resample method bicubic sharper
						--If...else if statement could be expanded to handle other file types. 
						if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "Photoshop format" then
							set myImageDocument to save docRef in file myFileName as Photoshop format
						else if myLinkType = "EPS" then
							set myImageDocument to save docRef in file myFileName as Photoshop EPS with options {class:EPS save options, encoding:binary, preview type:JPEG Mac OS}
						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, rotation angle:FrameRot, shear angle:FrameShear}
					set properties of theImage to {horizontal scale:myFinalHorizFlip, vertical scale:myFinalHorizVert, geometric bounds:ImgPos}
					resize theImage horizontal scale 100 vertical scale 100 around center anchor without considering current scale and considering parents scale
					copy myFileName to end of myProcessedLinks
				else if ImagePath is in myProcessedLinks then
					set myLink to update myLink
				end if
			end if
		end repeat
		--Resets the units  
		if myResetUnits is true then
			tell view preferences of mydocument to set properties to myOldViewPreferences
		end if
	end tell
	if myResetTransform is true then
		tell transform preferences to set properties to myOldTransPreferences
	end if
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
	set myHoriz to (round myHoriz) as string
	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
tell application "InDesign CS"
	activate
	beep
	display dialog "Done!"
end tell

Jeff (aka lesta)

OK, I’ve found a couple of things that broke probably because of Tiger or/and CS2.

This version if for ID CS2 and PS CS2 working together.

BTW, Robert, where you scale the image and resample them in one step is better, but you have to remove the /100 or the image is scaled to much, at least in the tests I’ve run.

I also kept your idea of scaling the image even if it was not proportional, which at the time I didn’t want to do. So thanks for your comment and making this script even more effective.

As for your other request (tiff bitmap vs 8-16bit) I have no idea at the time how I could do this.

One thing that would be cool would be to have a dialog saying which image where scaled proportionaly, which were scaled non-proportionaly and if there were some image not scaled by the script. That way, we could just glace at the dialog and know if we have a problem somewhere.

If you have other comment, please post.

Oh, and the script doesn’t work for images placed in a frame, that is in its turn placed in another frame. So becarful with that.

Jeff


--ResampleImages23.as 
--Resamples all images in the active document (using Photoshop) 
--to their scaled size; sets the scaling on all frames to 100%. 
--version updated to work on tiff, psd and eps from Photoshop
set myProcessedLinks to {}
set myFolder to choose folder with prompt "Select a destination folder for resampled images"
tell application "Adobe InDesign CS2"
	
	--If transformation preferences are not set to transformations are totals 
	--we have to set them for the script to work.
	if transformations are totals of transform preferences is false then
		set myOldTransPreferences to properties of transform preferences
		set transformations are totals of transform preferences to true
		set show content offset of transform preferences to true
		set dimensions include stroke weight of transform preferences to true
		set transform content of transform preferences to true
		set myResetTransform to true
	else
		set myResetTransform to false
	end if
	set mydocument to active document
	tell mydocument
		--If the measurement units of the active document are not inches, set the  
		--measurement units to inches. Units MUST be inches in order to script work. 
		if horizontal measurement units of view preferences of mydocument is not points or ¬
			vertical measurement units of view preferences of mydocument is not points then
			set myOldViewPreferences to properties of view preferences of mydocument
			set horizontal measurement units of view preferences of mydocument to points
			set vertical measurement units of view preferences of mydocument to points
			set myResetUnits to true
		else
			set myResetUnits to false
		end if
		
		
		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 myLinkedFile to file path of myLink as alias
			set myLinkType to link type of myLink
			tell application "Finder" to set fileCreator to file creator of (info for myLinkedFile)
			--If statement expanded to isolate PS EPS from AI EPS. 
			if (myLinkType = "TIFF") or (myLinkType = "Photoshop") or ((myLinkType = "EPS") and (fileCreator = "8BIM")) then
				set LinkName to name of myLink
				set theImage to parent of myLink
				set theFrame to parent of theImage
				-- resets the graphic frame to 100 
				reset scaling of theFrame
				--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 absolute horizontal scale of theImage
				if myHoriz is less than 0 then
					set myImageFlipHoriz to -100
				else
					set myImageFlipHoriz to 100
				end if
				
				set myVert to absolute vertical scale of theImage
				if myVert is less than 0 then
					set myImageFlipVert to -100
				else
					set myImageFlipVert to 100
				end if
				
				-- Check if frame as been flipped
				if the absolute horizontal scale of theFrame is -100 then
					set myHorizFrameHeight to 100
					set myFrameFlipHoriz to -100
				else
					set myHorizFrameHeight to (absolute horizontal scale of theFrame)
					set myFrameFlipHoriz to 100
				end if
				
				if the absolute vertical scale of theFrame is -100 then
					set myVertFrameWidth to 100
					set myframeFlipVert to -100
				else
					set myVertFrameWidth to (absolute vertical scale of theFrame)
					set myframeFlipVert to 100
				end if
				
				if (myImageFlipHoriz + myFrameFlipHoriz) is 0 then
					set myFinalHorizFlip to -100
				else
					set myFinalHorizFlip to 100
				end if
				
				if (myImageFlipVert + myframeFlipVert) is 0 then
					set myFinalHorizVert to -100
				else
					set myFinalHorizVert to 100
				end if
				
				--get the rotation and Shear of the frame 
				set FrameRot to rotation angle of theFrame
				set FrameShear to shear angle of theFrame
				
				--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 myHorizFrameHeight is 100 and myHorizFrameHeight = myVertFrameWidth and ImagePath is not in myProcessedLinks and myHoriz is not 100 then
					set myFileName to my myMakeFileName(myFolder, ImagePath as alias, myHoriz)
					
					--...then scale the graphic in Photoshop: 
					tell application "Adobe Photoshop CS2"
						--activate 
						set ruler units of settings to point units
						open file ImagePath showing dialogs never
						set docRef to current document
						--resizing images that are proportionally scaled
						--resize image docRef width percent (myHoriz / 100) resample method none
						--resize image docRef resolution 300 resample method bicubic sharper
						
						--resizing images proportionaly and non proportionaly scaled
						resize image docRef width percent (myHoriz) height percent (myVert) resolution 300 resample method bicubic sharper
						
						--If...else if statement could be expanded to handle other file types. 
						if myLinkType = "TIFF" then
							set myImageDocument to save docRef in file myFileName as TIFF
						else if myLinkType = "Photoshop" then
							set myImageDocument to save docRef in file myFileName as Photoshop format
						else if myLinkType = "EPS" then
							set myImageDocument to save docRef in file myFileName as Photoshop EPS with options {class:EPS save options, encoding:binary, preview type:JPEG Mac OS}
						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, rotation angle:FrameRot, shear angle:FrameShear}
					set properties of theImage to {horizontal scale:myFinalHorizFlip, vertical scale:myFinalHorizVert, geometric bounds:ImgPos}
					resize theImage horizontal scale 100 vertical scale 100 around center anchor without considering current scale and considering parents scale
					copy myFileName to end of myProcessedLinks
				else if ImagePath is in myProcessedLinks then
					set myLink to update myLink
				end if
			end if
		end repeat
		--Resets the units  
		if myResetUnits is true then
			tell view preferences of mydocument to set properties to myOldViewPreferences
		end if
	end tell
	if myResetTransform is true then
		tell transform preferences to set properties to myOldTransPreferences
	end if
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
	set myHoriz to (round myHoriz) as string
	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
tell application "Adobe InDesign CS2"
	activate
	beep
	display dialog "Done!"
end tell

I’ve been using the 2.0 version of the script with great success but recently came across a problem I can’t fix. Even in the more recent scripts posted it still fails. The script seems to randomly ignore certain files in my documents. I have images that are the same color space, same resolution, approx. same %, i’ve tried removing all paths or making them identical just to test them but still no luck. Has anyone else found this problem and figured out why it did it? Please help if you have. Thanks.

I figured out it was an image that the script thought was inside another frame (or was but I couldn’t determine).
I do have another request if someone could help me add this functionality…

  1. The ability to choose the resolution (resample) setting when the script starts. We adjust our images based on line screen and would be helpful.
  2. A progress bar to know how long it will take.

krdzine,

I’ve run into this problem also, and I didn’t have time to figure out a way to fix it yet. In all the time I used this script, it happened only once.

As for your request, the first is a good idea, the second would require a OSAX extension, so I don’t want to impose any spectial install with the script. It as to work as is.

I might have some time to check this out in the following 2 weeks, so I’ll you posted.

Jeff

Any luck on figuring out the option to select the resample dpi?