# How to scale down an image by aspect ratio exactly?

I have an image that is (just for example, can be any size):

599 original width
599 original height

and a destination aspect ratio for example (can be any):

1:2

I want to scale down the image and make it exactly the aspect ratio, a simple multiplication gives only:

299.5 x 599

while I expect

299 x 598

How to get the expected result?

Sorry for my bad English, I find it hard for me to describe a mathematics question well.

## 1 Answer

You don't say what the class of problems you are working on, but one approach is to divide $599$ by $2$ and round down because you can't have fractional pixels. That gives the new dimension in that direction as $299$. Then multiply that by $2$ to get the size in the other direction, giving $598$. This gives the largest rectangle of proportion $1:2$ that fits in $599 \times 599$

• I couldn't figure out what is "class of problems", sorry for my bad English. But I see your solution, it is simpler than I imagine, thanks! Also I saw my question got downvotes, don't understand why but maybe it's too easy I guess lol – Edward Mar 28 '18 at 5:21
• Your problem had a square aspect ratio to start. The aspect ratio you wanted had a $1$ in one proportion instead of something like $3:4$ I don't know the range of problems you want to work with, so can't make sure my solution is sufficient for the whole range. – Ross Millikan Mar 28 '18 at 5:25
• Thanks for the explanation, the aspect ratio can be any, I just tried another aspect ratio 2:3, this time it didn't give me the expect result, but I managed to get that by repeating the method twice. It will finally find both dimension integer number by keeping round down and multiplying, right? – Edward Mar 28 '18 at 5:43
• When you have aspect ratio $2:3$ it should work in one step. You should divide by the larger number and round down, so $599/3=199$. Your dimensions are then $2\cdot 199=398$ by $3 \cdot 199=597$ – Ross Millikan Mar 28 '18 at 13:53