Sunday, January 6, 2008

Apple Script : Photoshop Batch Resizer

It's easy to put together a batch process in Photoshop to resize all the images in a folder to a certain height or width. However, if some of the photos are portraits and some are landscapes, they end up at different sizes. This script determines which dimension is the longest one and resizes that dimension to the specified number of pixels (set by the user).

set target_size to text returned of (display dialog "Enter target size of longest side in pixels:" default answer 2400)
set raw_folder to choose folder with prompt "Select originals folder:"
set live_folder to choose folder with prompt "Select target folder:"
tell application "Finder"
set itemList to files in raw_folder
end tell
repeat with an_item in itemList
tell application "Finder"
set current to an_item as alias
end tell

tell application "Adobe Photoshop CS"
activate
open current
set this_image to current document
set long_side to height of current document
set long_side_identity to 1
if width of current document > long_side then set long_side_identity to 2
if width of current document > long_side then set long_side to width of current document
if long_side > target_size as integer and long_side_identity = 1 then
resize image this_image height target_size as integer
end if
if long_side > target_size as integer and long_side_identity = 2 then
resize image this_image width target_size as integer
end if
tell current document
save as JPEG in live_folder
close
end tell
end tell
end repeat
This is set to save the images as JPEGs in Adobe Photoshop CS -- if you want it to save them in some other format, just change the line Save as JPEG in live_folder to Save as TIFF..., Save as Photoshop format..., Save as Photoshop EPS..., etc. (See the AppleScript dictionary for Photoshop for a complete list of formats.) If you want to use this script in Adobe CS3, change the line tell application "Adobe Photoshop CS"

Thanks to macosxhints for tips and tricks

1 comment:

Anonymous said...

very nice color combinations making it unreadable.