Closed daveb84 closed 10 years ago
This is actually by design. If resizeheight > originalheight or resizewidth > originalwidth no resize will take place as upscaling images usually dont give good results
But that's not what is happening here.
The resize height is 75 and the original height is 93. It should shrink the height to 75, but it doesn't - the resulting image is 93.
Its because the REAL height aspect ratio (1.24 in this example) gets rounded down to 1. Therefore, the heightRatio > widthRatio condition fails incorrectly and ResizeImageByWidth is called instead of ResizeImageByHeight.
I'm guessing height aspect ratios greater than 1.5 would be fine because the value of heightRatio would get rounded to 2, therefore resulting in ResizeByHeight being called correctly
I have removed the restriction on upscaling images and added a fix for calculating size for ScaleToFit. An updated NuGet package is now available.Could you check it out?
Works like a charm! Thanks dude.
When I resize an image using scale to fit that is too tall, the height of the resized image is not shrunk accordingly.
I found this when resizing a 116 x 93 pixel image to fit 340 x 75:
Expected: image should be 75 px high. Actual: image is 93 px high.
Looking through the code, it looks like the source of the problem is not casting the widths/heights to double in the ImageResizer.ScaleToFit method. This causes the height ratio to be 1.0 rather than 1.24:
Fixed version: