Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an image with width 4096 and height 2896. I would like to scale the image to below 4000 pixels wide - and as close to 4000 as possible. I would also like to keep the dimensions whole numbers.

Is there an equation to do this?


More Details

  • Clarification: I do not care if I divide by a rational number.

  • Reason: I am doing this due to a software limitation. The software that we make the image with can not have a width or height 4000px or more. But the size I want is 4096. To try and make the final image as crisp as possible, I reasoned that you should not have any rounding.

share|cite|improve this question

If we want to scale down as in divide by an integer, then you have very few choices. To say that we want to divide a number by a whole number and get a whole number out is to say that we want to divide a number by one of its factors. $4096$ is a $2$-power, so you're only choices there are powers of $2$.

Unfortunately, $2896 = 2^4181$, so the only divisors of $2896$ that are also divisors of $4096$ are $1, 2, 4, 8, 16$. (And now I see Jennifer's answer - but I'm not done yet).

But if we are a bit looser in our idea of scaling, as in divide by some rational number, then we have a few more choices. It's still true that our numerator will be one of $1,2,4,8,16$. But we can more or less arbitrarily choose our denominator. For example, we might choose to scale down by a factor of $16/15$.

$4096 \cdot 15/16 = 3840$, and $2896 \cdot 15/16 = 2715$. So it's a bit smaller than what you would have wanted, but it maintains the correct aspect ratio.

What is the cost here? It's not clear (to me, at least) how one defines the new colors for this new picture on a pixel by pixel basis, but perhaps that is something that people already know how to cope with.

share|cite|improve this answer
Thanks for the answer! - It took me a while to understand, but I think this is what I need to do: Find the highest common denominator and then create the biggest fraction from that (in this case 15/16). Please correct me if i am wrong. – lindon fox Aug 29 '12 at 7:12

You can't keep it close $4000$. We have $4096 = 2^{12}$, $2896 = 2^4 \times 181$, i.e. the gcd of width, height is $2^4.$ If I understand you correctly, the scaling factors are $2, 4, 8,$ and $16$.

Can't you just scale it by .9 or something, and then round numbers up or down?

share|cite|improve this answer
Let me know if answer doesn't make sense at all. I will just delete it! – user2468 Aug 29 '12 at 5:27

Well, 4096/2896 $\approx$ 1.41436. The closest whole number ratio to that with width 4000 is 4000/2828

share|cite|improve this answer

Your Answer


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.