I have an image which when I try to resize using the DOPUS context menu "Convert image..." and maintain aspect ratio, the resulting image is 1px short vertically:
Starting image is PNG, 2731 x 2048
If I use Paint.NET to resize this, keeping the checkbox 'maintain aspect ratio' checked, and selecting 400 for width, the result is a 400 x 300 image (in this case the app automatically fills in 300 for height and does create a 400 x 300 image). Likewise if I select 1024, I get a 1024 x 768 image. These are both the expected outcome.
If I use the DOPUS "Convert image..." dialog, keep "preserve aspect ratio" checked, and select 1024 x 768, the result is a 1024 x 767 image, which is not the desired outcome.
In the same scenario, if I opt for a custom size and select 400 x 300, what I get is a 400 x 299 image, which is not the desired outcome.
Note in convert image I am selecting JPG as the output format.
Personally, I would not expect it to round down. I didn't know it, but I'm so used to it rounding up. As an example, IrfanView wants to round up (see below). I would even venture to say that rounding down is not actually preserving the aspect ratio.
If I do 400 x 299 in Irfanview and then resize it (preserving aspect ration) back to 2048 height, my width is quite a bit off:
But if I stick with 400 x 300 and then resize it back up, original width is kept:
Thanks Leo. I anticipated this was due to rounding.
I would argue here that it is doing something the user does not expect ("don't surprise me!"); and also that 299.9634 is much closer to 300 than it is to 299.
Jon, to my point about what rounding that I think that most people would probably expect; here is Leo's worksheet but with decimals set to 0:
I don't want to get into a religious war about rounding. Just presenting to you that it surprised me, and my use case in this case required an outcome that I did not get. I love DOPUS and what you guys have done with it. Take my feedback on this little detail and do with it what you will.
Cheers,
Mike
I would be surprised if there is any other popular program out there that doesn't round up. The expected result should yield the same dimensions when resizing larger or you are not maintaining the aspect ration. Regarding my third screenshot above, 2740 x 2048 is an aspect ratio of 1.337890625 which is not 1.333333333.
Unfortunately as bitmaps are measured in whole pixels, it's not possible to maintain the exact aspect ratio unless you resize to a multiple of the original size. 2731 x 2048 is 1.33349609375, which isn't 1.333333333 either.
From my days of learning about decimals in Maths lessons ( in the mists of time ) we were taught that when rounding up decimal places .4 or less goes down and .5 goes up.
My thoughts are you should use the full ratio of 1.33349609375 for accuracy then round the result of 299.9634 to 300
That's not how integer maths on computers usually works. They round toward zero.
We could change the code to use floating point and round to the nearest number instead, but it seems very arbitrary to me (and floating point has issues of its own).
If you want an exact size, you can specify both dimensions exactly.