title: Proportional image resize
body: <p>I'm having a little bit of a problem scaling my images to a properly 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.</p>
  
  <p>I'm using this at the moment: </p>
  
  <pre><code>var maxHeight   = 300;
  var maxWidth    = 300;
  
  var ratio:Number    =   height / width;
  
  if (height &gt; maxHeight) {
      height = maxHeight;
      width = Math.round(height / ratio);
  } 
  
  else if(width &gt; maxWidth) {
      width = maxWidth;
      height = Math.round(width * ratio);
  }
  </code></pre>
  
  <p>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 images proportionally.</p>