Size Images in Photoshop using Centimeters rather than Pixels

Hi All

We are trying to create an Applescript that will tell Photoshop to size an image to a given dimensional width which we want to be in centimeters. We have managed to do this with the script below sizes to pixels rather than centimeters.

params is the variable that contains the width value.

If params is set to 3 we want the image to change the file to 3 cms wide and not 3 pixels wide.

Any ideas on how to do this?

Many thanks

Paul

on main(inputs, outputFolder, params)
repeat with input in inputs
tell application “Adobe Photoshop CS5.1”
– open an input file
set theImage to input
open file theImage

		-- do something, in this case an action
		-- set actionName to item 1 of params
		set newwidth to item 1 of params
		resize image current document width newwidth resample method bicubic
		
		-- save file in output folder with the same file name as the input
		set fileName to name of (info for input)
		set output to outputFolder & "/" & fileName
		save document 1 in output as JPEG
		close document 1 saving no
	end tell
end repeat

end main

Hi Paul,

Welcome to MacScripter!

Think you might need to set the ruler units to cm units.

This is untested but try this:


on main(inputs, outputFolder, params)
    repeat with input in inputs
        tell application "Adobe Photoshop CS5.1"

set ruler units of settings to cm units -- change the ruler units
            -- open an input file
            set theImage to input
            open file theImage
            
            -- do something, in this case an action
            -- set actionName to item 1 of params
            set newwidth to item 1 of params
            resize image current document width newwidth resample method bicubic
            
            -- save file in output folder with the same file name as the input
            set fileName to name of (info for input)
            set output to outputFolder & "/" & fileName
            save document 1 in output as JPEG
            close document 1 saving no
        end tell
    end repeat

end main

HTH

Hi,

try to coerce newwidth as centimeters

set newwidth to (item 1 of params) as centimeters

Hi All

Many thanks for your help with this.

We really struggled to get the process to work in cms or any other dimensional unit so we gave up and used the default points measurement. Works like a dream now we have multiplied the input variable by 28.346 to convert cms to points.

This is what we ended up with…

on main(inputs, outputFolder, params)
repeat with input in inputs
tell application “Adobe Photoshop CS5.1”
set theImage to input
open file theImage
resize image current document width (item 1 of params) resample method none
set fileName to name of (info for input)
set output to outputFolder & “/” & fileName
save document 1 in output as JPEG
close document 1 saving no
end tell
end repeat
end main

Best wishes

Paul