title: PHP resize image proportionally to a bigger size
body: <p>I'm currently working on a script that shows thumbnails from a website on a mobile app, and I'm having problems with the "retina display". If the original image is big enough, I show a thumbnail with the double of the required size, and if it is not, I show it on the required size. Now, my function checks if it can be resized proportionally and if it can't, I resize it to the "min-width" or "min-height" and crop it from the center.</p>
  
  <p>Here is the problem: if it detects that the image can't be shown on the double of size, "scale up" the cropped size until it reaches the limits of the original size, and I can't find a way to scale it right. (My main problem is that I'm not really good at maths :P).</p>
  
  <p>For a more simple lecture:</p>
  
  <ul>
  <li>This is the original size of the image: <strong>600 x 301</strong></li>
  <li>This is the required/cropped size: <strong>320 x 180</strong></li>
  <li>This is the size I want to get: <strong>535 x 301</strong>. I got it from Photoshop, and is the result of scaling 320x180 up until it finds the limit of the original size.</li>
  </ul>
  
  <p>PS: I know GD, so I only need the formula to calculate the size. </p>