I'm having a wee bit of a problem scaling my images to a proper predefined size. I was wondering -since it is purely mathematics-, if there's some sort of common logical algorithm that works in every language (php, actionscript, javascript etc.) to scale images proportionally.
I'm using this at the moment:
var maxHeight = 300;
var maxWidth = 300;
var ratio:Number = height / width;
if (height > maxHeight) {
height = maxHeight;
width = Math.round(height / ratio);
}
else if(width > maxWidth) {
width = maxWidth;
height = Math.round(width * ratio);
}
But it doesn't work properly. The images scales proportionately, sure enough, but the size isn't set at 300 (either in width or in height). It kind of makes sense, but I was wondering if there's a fool-proof, easy way to scale your images proportionally.