Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Keeping image ratio's (https://www.warriorforum.com/programming/439059-keeping-image-ratios.html)

foiodisar 24th August 2011 10:27 PM

Keeping image ratio's
 
Does anyone know the calculation to use for keeping image sizes?

Let's say I wanted to give an image a width of 300pixels, but keep the proportionate height.

I've looked at sample scripts but they all go into way too much detail, and I can't really be bothered sifting through all of the code just to see where the calculation comes in!

unnatural 25th August 2011 04:01 PM

Re: Keeping image ratio's
 
It's actually pretty simple.

Take your desired width (300 pixels) and divide by the current width (eg. 900 pixels).

Then take that result and multiply it by your height to achieve the same ratio.

So for example:

You have an image 600 (width) X 780 (height) and you want the new image to have a with of 300.

So..

300 / 600 = 0.5
0.5 * 780 = 390 (new height)

Hope that helps!

sylarrr 26th August 2011 08:42 AM

Re: Keeping image ratio's
 
Quote:

Originally Posted by unnatural (Post 4544788)
It's actually pretty simple.

Take your desired width (300 pixels) and divide by the current width (eg. 900 pixels).

Then take that result and multiply it by your height to achieve the same ratio.

So for example:

You have an image 600 (width) X 780 (height) and you want the new image to have a with of 300.

So..

300 / 600 = 0.5
0.5 * 780 = 390 (new height)

Hope that helps!

Thats correct. But why do you need it?

TigerNone 27th August 2011 03:36 PM

Re: Keeping image ratio's
 
In HTML, if you just specify the width in the image tag, it will scale it proportionally. For example: <img src="image.png" width="300" />


All times are GMT -6. The time now is 09:13 PM.