Resize Images Photoshop CS3

Below is a script (Thanks Mark) that saves several filetypes with different sizes.
The jpg’s are resized to 100, 50 and 25 %
I need to change the following:
If the height is bigger than the with: resize height to 400, 180 and 80 pixels res 72
else ( width is bigger than height or equal): resize width to 500, 225 and 100 pixels res 72

Many thanks in advance,
Peter

property theFileType_A : {"8BPS"}
property theFileType_B : {"EPSF"}

set Input_Folder to choose folder with prompt "Choose a Folder w Images" without invisibles

tell application "Finder"
	if not (exists folder "LAY_OUT" of Input_Folder) then
		set x to make new folder at Input_Folder with properties {name:"LAY_OUT"}
		set EPS_Folder to x as text
	else
		set EPS_Folder to folder "LAY_OUT" of Input_Folder as text
	end if
	if not (exists folder "JPEG_OUT" of Input_Folder) then
		set y to make new folder at Input_Folder with properties {name:"JPEG_OUT"}
		set JPEG_Folder to y as text
	else
		set JPEG_Folder to folder "JPEG_OUT" of folder Input_Folder as text
	end if
	set File_List to files in Input_Folder whose file type is in theFileType_B
end tell

repeat with This_File in File_List
	tell application "Finder"
		set The_File to This_File as alias
	end tell
	tell application "Adobe Photoshop CS3"
		with timeout of 3600 seconds
			activate
			set display dialogs to never
			set User_Rulers to ruler units of settings
			set ruler units of settings to pixel units
			open The_File
			set Doc_Ref to the current document
			tell Doc_Ref
				set Doc_Name to name
				set Base_Name to my getBaseName(Doc_Name)
				tell Doc_Ref
					convert to profile "sRGB IEC61966-2.1" intent perceptual with blackpoint compensation and dithering
					if (bits per channel is sixteen) then
						set bits per channel to eight
					end if
					resize image resolution 72 resample method bicubic
					set Saved_State_1 to current history state
					set New_Path to EPS_Folder & Base_Name & ".eps.lay"
					save Doc_Ref in file New_Path as Photoshop EPS with options {class:EPS save options, embed color profile:true, encoding:medium quality JPEG, preview type:eight bit TIFF} appending no extension with copying
					set current history state to Saved_State_1
					if exists (path items whose kind is clipping) then
						set Clip to (name of every path item whose kind is clipping)
						create selection path item (item 1 of Clip) feather amount 0 with antialiasing
						invert selection
						fill selection with contents {class:RGB color, red:255, green:255, blue:255}
						deselect
					end if
					set Pixel_Height to height
					set Saved_State_2 to current history state
					set New_Path to JPEG_Folder & Base_Name & "_100.jpg"
					save Doc_Ref in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
					set current history state to Saved_State_2
					resize image height Pixel_Height / 2 resolution 72
					set New_Path to JPEG_Folder & Base_Name & "_50.jpg"
					save Doc_Ref in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
					set current history state to Saved_State_2
					resize image height Pixel_Height / 4 resolution 72
					set New_Path to JPEG_Folder & Base_Name & "_25.jpg"
					save Doc_Ref in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
					close without saving
				end tell
			end tell
		end timeout
	end tell
end repeat
end

tell application "Finder"
	set File_List to files in Input_Folder whose file type is in theFileType_A
end tell

repeat with This_File in File_List
	tell application "Finder"
		set The_File to This_File as alias
	end tell
	tell application "Adobe Photoshop CS3"
		with timeout of 3600 seconds
			activate
			set display dialogs to never
			set User_Rulers to ruler units of settings
			set ruler units of settings to pixel units
			open The_File
			set Doc_Ref to the current document
			tell Doc_Ref
				set Doc_Name to name
				set Base_Name to my getBaseName(Doc_Name)
				tell Doc_Ref
					convert to profile "sRGB IEC61966-2.1" intent perceptual with blackpoint compensation and dithering
					if (bits per channel is sixteen) then
						set bits per channel to eight
					end if
					resize image resolution 72 resample method bicubic
					set Saved_State_1 to current history state
					set New_Path to EPS_Folder & Base_Name & ".psd.lay"
					save Doc_Ref in file New_Path as Photoshop format with options {class:Photoshop save options, save alpha channels:true, save layers:true, embed color profile:true} appending no extension with copying
					set current history state to Saved_State_1
					if exists (path items whose kind is clipping) then
						set Clip to (name of every path item whose kind is clipping)
						create selection path item (item 1 of Clip) feather amount 0 with antialiasing
						invert selection
						fill selection with contents {class:RGB color, red:255, green:255, blue:255}
						deselect
					end if
					set Pixel_Height to height
					set Saved_State_2 to current history state
					set New_Path to JPEG_Folder & Base_Name & "_100.jpg"
					save Doc_Ref in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
					set current history state to Saved_State_2
					resize image height Pixel_Height / 2 resolution 72
					set New_Path to JPEG_Folder & Base_Name & "_50.jpg"
					save Doc_Ref in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
					set current history state to Saved_State_2
					resize image height Pixel_Height / 4 resolution 72
					set New_Path to JPEG_Folder & Base_Name & "_25.jpg"
					save Doc_Ref in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
					close without saving
				end tell
			end tell
		end timeout
	end tell
end repeat
end

tell application "Adobe Photoshop CS3"
	set ruler units of settings to User_Rulers
end tell

on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

tell application (path to frontmost application as Unicode text)
	display dialog "Beelden zijn verwerk" buttons {"OK"} default button 1
end tell


Hi Peter,

try this


property theFileType_A : {"8BPS"}
property theFileType_B : {"EPSF"}
property newName : ""
property Saved_State_2 : missing value

set Input_Folder to (choose folder with prompt "Choose a Folder w Images" without invisibles) as text

set EPS_Folder to Input_Folder & "LAY_OUT:"
set JPEG_Folder to Input_Folder & "JPEG_OUT:"

do shell script "/bin/mkdir -p " & quoted form of POSIX path of Input_Folder & "/{LAY_OUT,JPEG_OUT}/"
tell application "Finder" to set File_List to files in folder Input_Folder

tell application "Adobe Photoshop CS3"
	activate
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	repeat with This_File in File_List
		set theFileType to file type of (info for This_File as alias)
		if theFileType is in theFileType_A or theFileType is in theFileType_B then
			with timeout of 3600 seconds
				open (This_File as alias)
				set Doc_Ref to the current document
				tell Doc_Ref
					set Doc_Name to name
					set Base_Name to my getBaseName(Doc_Name)
					convert to profile "sRGB IEC61966-2.1" intent perceptual with blackpoint compensation and dithering
					if (bits per channel is sixteen) then
						set bits per channel to eight
					end if
					resize image resolution 72 resample method bicubic
					set Saved_State_1 to current history state
					if theFileType is in theFileType_B then
						set New_Path to EPS_Folder & Base_Name & ".eps.lay"
						save Doc_Ref in file New_Path as Photoshop EPS with options {class:EPS save options, embed color profile:true, encoding:medium quality JPEG, preview type:eight bit TIFF} appending no extension with copying
					else
						set New_Path to EPS_Folder & Base_Name & ".psd.lay"
						save Doc_Ref in file New_Path as Photoshop format with options {class:Photoshop save options, save alpha channels:true, save layers:true, embed color profile:true} appending no extension with copying
					end if
					set current history state to Saved_State_1
					if exists (path items whose kind is clipping) then
						set Clip to (name of every path item whose kind is clipping)
						create selection path item (item 1 of Clip) feather amount 0 with antialiasing
						invert selection
						fill selection with contents {class:RGB color, red:255, green:255, blue:255}
						deselect
					end if
					set Pixel_Height to height
					set Pixel_Width to width
					
					set newName to JPEG_Folder & Base_Name
					set Saved_State_2 to current history state
				end tell
				if Pixel_Height > Pixel_Width then
					my Resize_Save_Doc(Doc_Ref, 400, 72)
					my Resize_Save_Doc(Doc_Ref, 180, 72)
					my Resize_Save_Doc(Doc_Ref, 80, 72)
					
				else
					my Resize_Save_Doc(Doc_Ref, 500, 72)
					my Resize_Save_Doc(Doc_Ref, 225, 72)
					my Resize_Save_Doc(Doc_Ref, 100, 72)
				end if
				close Doc_Ref without saving
			end timeout
		end if
	end repeat
	set ruler units of settings to User_Rulers
end tell


on Resize_Save_Doc(doc, _height, _res)
	tell application "Adobe Photoshop CS3"
		tell doc to resize image height _height resolution _res
		set New_Path to newName & "_" & _height & ".jpg"
		save doc in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
		tell doc to set current history state to Saved_State_2
	end tell
end Resize_Save_Doc

on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

tell application (path to frontmost application as Unicode text)
	display dialog "Beelden zijn verwerk" buttons {"OK"} default button 1
end tell


Thanks Stefan,

Great job.
Your script is much ‘cleaner’ than mine and works but…
When resizing a landscape image it resizes the height to 500, 225 and 100 pix, instead of the width
If possible set the name not to use the _height but the actual choosen height or width.
If that’s to complicated _L, _M, and _S would also be sufficient.

Peter
:):slight_smile:

It’s fixed

The new file name does include the actual choosen height or width


.
					set newName to JPEG_Folder & Base_Name
					set Saved_State_2 to current history state
				end tell
				if Pixel_Height > Pixel_Width then
					my Resize_Save_Doc(Doc_Ref, 400, 72, true)
					my Resize_Save_Doc(Doc_Ref, 180, 72, true)
					my Resize_Save_Doc(Doc_Ref, 80, 72, true)
					
				else
					my Resize_Save_Doc(Doc_Ref, 500, 72, false)
					my Resize_Save_Doc(Doc_Ref, 225, 72, false)
					my Resize_Save_Doc(Doc_Ref, 100, 72, false)
				end if
				close Doc_Ref without saving
			end timeout
		end if
	end repeat
	set ruler units of settings to User_Rulers
end tell


on Resize_Save_Doc(doc, resizeValue, _res, _flag)
	tell application "Adobe Photoshop CS3"
		if _flag then
			tell doc to resize image height resizeValue resolution _res
		else
			tell doc to resize image width resizeValue resolution _res
		end if
		set New_Path to newName & "_" & resizeValue & ".jpg"
		save doc in file New_Path as JPEG with options {quality:6, embed color profile:true} with copying
		tell doc to set current history state to Saved_State_2
	end tell
end Resize_Save_Doc

.

Wow
Thanks Stefan,
You’r faster than lightning.
Many thanks for your input
:):):):slight_smile:
Peter