0

Hey all i am trying to figure out how to resize an image that has a higher height than width. The normal width and height of the area where the image needs to be displayed is:

width  = 1000px
height = 700px

What type of math would i need in order to resize that to the proper width/height above without screwing it?

The test image size is:

 width  = 1451
 height = 2200

I was thinking of doing this:

(700/org.height)

But that does not come up with the correct number of 462.

In photoshop, changing the height to 700 yields a width value of 462.

StealthRT
  • 10,108
  • 40
  • 183
  • 342
  • http://stackoverflow.com/questions/7863653/algorithm-to-resize-image-and-maintain-aspect-ratio-to-fit-iphone - it doesn't matter which language you apply this to. the math is the same. You know, though, imagemagick can do this very easily for you. – Kai Qing Dec 14 '12 at 02:01
  • http://stackoverflow.com/questions/8674856/php-uploading-images-in-the-correct-dimensions My answer in this question should assist you with producing the dimension within the confines of a maximum size – Scuzzy Dec 14 '12 at 02:07

2 Answers2

1

so you want to scale your image so that it fits as large as possible within a 1000x700 square without stretching it? You could do something like this:

$availH = 700;
$availW = 1000;
$imageH = 2200;
$imageW = 1451;

// you know you want to limit the height to 700
$newH = $availH;

// figure out what the ratio was that you adjusted (will equal aprox 0.3181)
$ratio = $availH / $imageH;

// now that you have the $ratio you can apply that to the width (will equal 462)
$newW = round(imageW * $ratio);

Now you have $newW and $newH which are the new sizes for your image properly scaled. You could of course condense this down but I've written it out so each step is more clear.

Jason
  • 1,726
  • 17
  • 19
0

Formula to keep aspect ratio when resizing is

original height / original width x new width = new height

Source: http://andrew.hedges.name/experiments/aspect_ratio/

But you want to switch it around to the following I think:

original width / original height x new height = new width
Rowan
  • 598
  • 5
  • 7