Can someone help me with an equation. I’d like to resize an image down so that it has a minimum width or height of 200px. So, if the original is 500 x 300 it’d end up being 333 x 200 and if the original was 500 x 900 it’d end up being 200 x 360 and so on. If either of the original dimensions are smaller than 200px, no resizing is done.
I’d appreciate any input on this. I am sure its quite simple, I just can’t seem to work it out.
You just need to work out the existing image ratio and do the math from that. The ratio is the images width compared to height or vice versa (usually which ever is longer is divided by the shorter to give you a ratio >= 1). for example width 450 and height 300 has a ratio of 1.5 wide. meaning that the image is 1.5 times wider than it is tall. Then you can multiply your “minimum” value by the ratio to get the other size or as in the example if your height is 200 the other side will be minimum * ratio or 200 * 1.5 which makes the size 300 wide and 200 tall.
http://codepad.viper-7.com/RsxAsC