Geometry help!

ok so I have a script that resize images and photoshop CS2 I want to allow the user to supply just the width or just the height. But when I resize want to constrain the proportions but I don’t know how to do the math :slight_smile: I think i"m on the right track but I’m probably way off

heres what I’ve got


set widthPix to ""
set heightPix to "200" as real

tell application "Adobe Photoshop CS2"
	activate
	set ruler units of settings to pixel units
	set display dialogs to never
	tell document 1
		set CW to (width as pixels)
		set CH to (height as pixels)
		
		if widthPix is "" and heightPix is not "" then
			set widthPix to (((CH / CW) * heightPix) + CW)
		end if-

		
		resize image width widthPix height heightPix
	end tell
end tell

thank you all
MM

Hi,

widthPix = CW * heightPix / CH
heightPix = CH * widthPix / CW

http://en.wikipedia.org/wiki/Rule_of_three_(mathematics) :wink:

StefanK,

thanks you very much I was able to figure it out using the link you were close though :smiley:


set widthPix to ""
set heightPix to "200" as real

tell application "Adobe Photoshop CS2"
	activate
	set ruler units of settings to pixel units
	set display dialogs to never
	tell document 1
		set CW to (width as pixels)
		set CH to (height as pixels)
		
		if widthPix is "" and heightPix is not "" then
			--widthPix = CW * heightPix / CH
			set widthPix to (CW / heightPix) * CW
			
		end if
		
		
		resize image width widthPix height heightPix
	end tell
end tell

MM

Just resize either height or width constrian proportions is default. no math required.

tell application "Adobe Photoshop CS2"
	activate
	tell document 1
		resize image height 400
	end tell
end tell