I'm looking for help/suggestions in finding the most efficient way to resize an image to be as small as possible using PHP/GD while preserving the aspect ratio of the original image but ensuring the the resized image is bigger than a defined minimum width & height.
For example, the resized image must have a width >= 400 and a height >= 300 but should be as close to those dimensions as possible while maintaining the original aspect ratio.
Such that a "landscape" image would have an ideal height of 300 or slightly larger with a width >= 400 and a "portrait" image would have an ideal width of 400 or slightly larger with a height >= 300.