Closed vasyvasilie closed 5 years ago
First of all, thank you for the contribution!
The Scale function takes the ratio value (a scale factor) as it's main argument. I believe it should return an image where both dimensions are scaled using the given ratio in the closest way possible (multiplying by ratio and rounding the result). At least this is what I would expect. E.g.
w := int(ratio*float64(img.Bounds().Dx()) + 0.5)
h := int(ratio*float64(img.Bounds().Dy()) + 0.5)
dst = Resize(src, w, h, filter)
As far as I can see this is what ImageMagick does with its percentage resize (`convert src.png -resize 50% dst.png).
On the other hand, it's just three lines of code, so I'm not sure we need to add another function to the API.
Addition of half-one and combined operations of floats and ints in this place gave for me not determined results with different percentages of scaling. My point was in combination of determined result and better xy-ratio after scaling, that's why i created this pr for mb help others get more accurate results.
But you're right, that's my code is only layer on your base code and can be simple realized
I guess it depends on the use case. I think the algorithm you provided, while it works for you, provides less predictable results. For example:
source image size | scaling factor | output image size |
---|---|---|
256x128 | 0.3 | 76x38 |
256x129 | 0.3 | 77x39 |
Both images have width = 265px, both are scaled with factor of 0.3 but the output image widths are different - 76px vs 77px. While I understand the intent of the algorithm, I believe it would be confusing for end-users.
Scale should scale image (up or down) with the best aspect ratio