Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have an image that is:

320 original width
407 original height

I want to let users resize the image via a form I am building on a webpage. They can adjust either the width or height. When they do the other dimension should auto adjust to maintain the aspect ratio.

When a user updates the width field I get the adjusted height like so:

aspect ratio = original width ÷ original height
adjusted height = <user chosen width> ÷ aspect ratio

Is this correct?

Also how to get the adjusted width when the user changes the height field? I know it should be simple enough but I just can't figure it out.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Yes, this is correct – though it unnecessarily uses two divisions instead of one division and a multiplication, adjusted height = <user-chosen width> * original height / original width.

The corresponding formula for the adjusted width is adjusted width = <user-chosen height> * original width / original height, or if you want to do it your way, adjusted width = <user-chosen height> * aspect ratio, with aspect ratio calculated as before.

share|improve this answer
    
perfect, thanks. –  JakeRow123 Aug 9 '12 at 19:43

Yes. You said you want the aspect ratio of the adjusted image to be the same as the aspect ratio of the original equation, so you want

$\frac{\text{adjusted width}}{\text{adjusted height}} = \frac{\text{original width}}{\text{original height}}$

Multiplying both sides of the equation by the adjusted height, you get

$\text{adjusted width} = \frac{\text{original width}}{\text{original height}} \cdot \text{adjusted height}$

Then, dividing both sides of the equation by $\frac{\text{original width}}{\text{original height}}$, you get

$\text{adjusted width } / \frac{\text{original width}}{\text{original height}} = \text{adjusted height},$

which is the formula you suggested!


So, how do you get the adjusted width when the user adjusts the height field? The answer is hidden in the reasoning above! Can you find it?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.