UIImage-Categories icon indicating copy to clipboard operation
UIImage-Categories copied to clipboard

Aspect fit scaling results in image one pixel too large

Open nathan-alden-sr opened this issue 11 years ago • 0 comments

This bug occurs with the resizedImageWithContentMode method.

I am passing an image whose dimensions are reported to be 4877x3515. When I supply a bounds parameter of 1000x1000, the resultant image's size is 1001x721.

I believe the bug is on this line:

CGSize newSize = CGSizeMake(self.size.width * ratio, self.size.height * ratio);

It looks like the resultant width is 1000.0001. The resultant width and height should be MINed with the bounds parameter:

CGSize newSize = CGSizeMake(MIN(bounds.width, self.size.width * ratio), MIN(bounds.height, self.size.height * ratio));

nathan-alden-sr avatar Nov 09 '13 04:11 nathan-alden-sr