How to resize an uploaded image based on the longest side? I can't seem to figure out how get ImageCache to resize an image based on the longest side.

Desired behaviour:

upload image 800x532 --&gt; resize image to 400x266 (landscape)
upload image 532x800 --&gt; resize image to 266x400 (portrait)


Is this possible with ImageCache? If not, how can I achieve this? Aspect ratio must be preserved.
To follow up on this question; ImageCache Actions now offers a feature called Aspect Switcher which allows for different image styles based on the original images aspect ratio, if it's portrait or landscape.