goose:
I do similar things with images. Give me an example of two different images in a folder, including width and height. Provide the desired sizes and I'll paste an example in here.
Note that if you use an option such as resize 800x800, it will resize images as follows:
one.jpg 1000x900
two.jpg 900x1000
Result:
one.jpg 800x720
two.jpg 720x800
If this is what you are looking for, then you don't need to know which size is longer. If, for example, you wanted each image to have a maximal width of 800, then you can just make the height portion of the scale option an unreasonable high number for you images.
Example:
Landscape-
Source: one.jpg JPEG 300x225
Command: mogrify -scale 200x1000 one.jpg
Result: one.jpg JPEG 200x150
Portrait-
Source: two.jpg JPEG 225x300
Command: mogrify -scale 200x1000 two.jpg
Result: two.jpg JPEG 200x267
As you can see, by setting the height to a number larger than a feasible proportional height, you get all images sized to 200 pixels in width regardless of orientation.
If for some reason you still need to know the longer side, I usually use the identity function to retrieve image information first. You can do this in your shell/perl script. Let us know if you need help.
Jim