Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 24th Aug 2011, 10:27 PM   #1
Warrior Member
 
Join Date: 2011
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Keeping image ratio's
Share on: 
fb share twitter share gplus share more share

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!
foiodisar is offline  
Unread 25th Aug 2011, 04:01 PM   #2
HyperActive Warrior
 
unnatural's Avatar
 
Join Date: 2011
Location: Edmonton, Alberta
Posts: 120
Thanks: 0
Thanked 25 Times in 23 Posts
Default
Re: Keeping image ratio's
Share on: 
fb share twitter share gplus share more share

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!

Last edited on 25th Aug 2011 at 04:02 PM. Reason: misspelled
unnatural is offline  
Unread 26th Aug 2011, 08:42 AM   #3
HyperActive Warrior
War Room Member
 
sylarrr's Avatar
 
Join Date: 2011
Posts: 220
Thanks: 14
Thanked 45 Times in 22 Posts
Default
Re: Keeping image ratio's
Share on: 
fb share twitter share gplus share more share

Originally Posted by unnatural View Post

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?

Use Androidâ„¢ smartphone?

Read Warrior Forums?


Warrior Forum Reader for Androidâ„¢ FREE
sylarrr is offline  
Unread 27th Aug 2011, 03:36 PM   #4
Warrior Member
War Room Member
 
Join Date: 2011
Posts: 29
Thanks: 0
Thanked 7 Times in 7 Posts
Default
Re: Keeping image ratio's
Share on: 
fb share twitter share gplus share more share

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" />
TigerNone is offline  
Closed Thread


Bookmarks

Tags
image, keeping, ratio


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:55 PM.