PhotoShop CS4 resize images

So, I’m having trouble figuring out the logic to do the following:

I have a number of images that need to be resized in PhotoShop. I want to script to look at the height and width and determine how to resize the file.

The hard part is that the images may have any proportions, and I want the script to make sure the resized image fits in let’s say a 100 pixel wide by 30 pixel high area.

If the image is really tall or really wide, it’s easy - if it is wider than tall then resize the width to 100 px and if it is taller than wide then resize to 30 px high.

The problem is if the image is is squarish. If the width is slightly larger than the height then resizing the width to 100 px will leave the height well over 30 px.

This doesn’t seem like it should be that hard but for some reason it is escaping me today…

Model: iMacintel
AppleScript: xCode 3.0
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)

Ha! It suddenly clicked. Here it is in case someone else is doing the same thing:

set theWidth to 100
set theHeight to 30
if (width of current document is greater than height of current document) and ((width of current document) / (height of current document) ≥ theWidth / theHeight) then
	resize image current document width theWidth resample method closest neighbor
else
	resize image current document height theHeight resample method closest neighbor
end if