Hi There,
I have a script that generates JPG’s with different dimensions.
In the current situation the JPEG’s are scaled like this:
If Width > Height : scale Width to 100, 225 and 500 pixels
iIf Width <= Height : scale Height to 80, 180 and 400 pixels
But they must fit within 100x80 ; 225x180 ; 500x400 (Ratio 5:4)
Is it possible to add the following:
if 4x Width > 5x Height : scale Width to 100, 225 and 500 pixels
if 4x Width <= 5x Height : scale Height to 80, 180 and 400 pixels
Example:
Image W200 x H190 pixels : 4x200=800 ; 5x190=950 → must be scaled to a Height of 80 pixels.
In the current situation the Width is scaled to 100 pixels and Height to 95 pixels.
This doesn’t fit in 100x80.
Can this be done ???
property theFileType_A : {"8BPS"}
property theFileType_B : {"EPSF"}
property newName : ""
property Saved_State_2 : missing value
set Input_Folder to (choose folder with prompt "Kies een Folder met Leen Bakker EPS of PSD beelden" without invisibles) as text
set LAY_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 180 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
					set Saved_State_1 to current history state
					resize image resolution 72 resample method bicubic sharper
					if theFileType is in theFileType_B then
						set New_Path to LAY_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:high quality JPEG, preview type:eight bit TIFF} appending no extension with copying
					else
						set New_Path to LAY_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, 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"
		set Doc_Ref to the current document
		set filterOptions to {class:filter options, amount:25, radius:1.0, threshold:0}
		tell Doc_Ref
			set Pixel_Height to height
			set Pixel_Width to width
			if _flag then
				tell doc to resize image height resizeValue resolution _res
				filter every layer using unsharp mask with options filterOptions
			else
				tell doc to resize image width resizeValue resolution _res
				filter every layer using unsharp mask with options filterOptions
			end if
			if height = 400 then
				set New_Path to newName & "_" & "Portrait" & "_" & "L" & ".jpg"
			end if
			if height = 180 then
				set New_Path to newName & "_" & "Portrait" & "_" & "M" & ".jpg"
			end if
			if height = 80 then
				set New_Path to newName & "_" & "Portrait" & "_" & "S" & ".jpg"
			end if
			if width = 500 then
				set New_Path to newName & "_" & "Landscape" & "_" & "L" & ".jpg"
			end if
			if width = 225 then
				set New_Path to newName & "_" & "Landscape" & "_" & "M" & ".jpg"
			end if
			if width = 100 then
				set New_Path to newName & "_" & "Landscape" & "_" & "S" & ".jpg"
			end if
			save doc in file New_Path as JPEG with options {quality:6, embed color profile:false} with copying
			tell doc to set current history state to Saved_State_2
		end tell
	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)
	with timeout of 3600 seconds
		display dialog "Beelden zijn verwerkt" buttons {"OK"} default button 1
	end timeout
end tell
