I would like to automate resizing images in Photoshop CS4. They will be horizontal/ vertical mix and will need to be resized to 9x12 inches horizontally or vertically based on the original, of course and then printed from Photoshop. How do I tell applescript what orientation the original images are to resize them accordingly?
tell application "Adobe Photoshop CS4"
activate
set display dialogs to never
set User_Rulers to ruler units of settings
set ruler units of settings to inch units
tell Doc_Ref
set Inch_Height to height
set Inch_Width to width
if height < width then
If your images are all 3:4 then you have the option to do this with an action no script required. You just insert menu item and navigate to fit image of file/automate just put the pixels dimensions of your longest edge in both fields.
Here’s a batch processing droplet that I made a while back to resize images to 640 pixels on the longest side. This should get you most of the way there.
-- This droplet processes both files or folders of files dropped onto the applet
on open these_items
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
tell application "Finder"
activate
end tell
beep 2
end open
-- this sub-routine processes folders
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end process_folder
on process_item(this_item)
set PathToDesktop to path to the desktop as text
tell application "Finder"
activate
if exists folder "JPEG_OUT" then
else
make new folder at desktop with properties {name:"JPEG_OUT"}
end if
end tell
tell application "Adobe Photoshop CS3"
activate
delay 2
set ruler units of settings to pixel units
open this_item
set AppleScript's text item delimiters to {":"}
set TempFileName to last text item of (this_item as string)
set AppleScript's text item delimiters to {"."}
set FinalFileName to first text item of (TempFileName as string)
if width of current document is greater than the height of current document then
resize image current document width 640 resample method bicubic
else
resize image current document height 640 resample method bicubic
end if
save current document in file (PathToDesktop & ":JPEG_OUT:" & FinalFileName & ".jpg") as JPEG with options {class:JPEG save options, embed color profile:false, format options:standard, quality:12} without copying
close current document saving no
end tell
end process_item
Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)
I know this is an ApplesScript forum but Photoshop already has built in functions to do what you want. Go to File > Automate > Fit Image… and enter the maximum size that you want the image to be in pixels.
However in your case you want 12 inches which is problematic because there is no direct translation to pixels as it’s dependent on DPI, but seeing as you say you want to print it, 300 DPI should be suffice. Therefore you should enter 3600 pixels (12*300) for both width and height into the Fit Image box.
You can then create an Action for this so that you can batch process however many images you want.
The only problem that I can see is that the shorter side is resized in accordance to the longest side (12 inches), so the original images need to be in the same dimension ratio for the shorter side to be 9 inches.
If you have calculated your pixels 12*300 = 3600 entered this in both fields. Then to get to 12" you just use “Image Size” and change the resolution field to 300 without resample.