Merge pull request #3354 from dreampiggy/bugfix_thumbnail_calculate
Fix the thumbnail pixel size calculation when preserveAspectRatio is true
This commit is contained in:
commit
eeb25d6e9c
|
@ -238,9 +238,9 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
|||
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
||||
CGFloat thumbnailRatio = thumbnailSize.width / thumbnailSize.height;
|
||||
if (pixelRatio > thumbnailRatio) {
|
||||
maxPixelSize = thumbnailSize.width;
|
||||
maxPixelSize = MAX(thumbnailSize.width, thumbnailSize.width / pixelRatio);
|
||||
} else {
|
||||
maxPixelSize = thumbnailSize.height;
|
||||
maxPixelSize = MAX(thumbnailSize.height, thumbnailSize.height * pixelRatio);
|
||||
}
|
||||
} else {
|
||||
maxPixelSize = MAX(thumbnailSize.width, thumbnailSize.height);
|
||||
|
@ -503,9 +503,9 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
|||
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
||||
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
|
||||
if (pixelRatio > maxPixelSizeRatio) {
|
||||
finalPixelSize = maxPixelSize.width;
|
||||
finalPixelSize = MAX(maxPixelSize.width, maxPixelSize.width / pixelRatio);
|
||||
} else {
|
||||
finalPixelSize = maxPixelSize.height;
|
||||
finalPixelSize = MAX(maxPixelSize.height, maxPixelSize.height * pixelRatio);
|
||||
}
|
||||
properties[(__bridge NSString *)kCGImageDestinationImageMaxPixelSize] = @(finalPixelSize);
|
||||
}
|
||||
|
|
|
@ -257,9 +257,9 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
|||
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
|
||||
CGFloat finalPixelSize;
|
||||
if (pixelRatio > maxPixelSizeRatio) {
|
||||
finalPixelSize = maxPixelSize.width;
|
||||
finalPixelSize = MAX(maxPixelSize.width, maxPixelSize.width / pixelRatio);
|
||||
} else {
|
||||
finalPixelSize = maxPixelSize.height;
|
||||
finalPixelSize = MAX(maxPixelSize.height, maxPixelSize.height * pixelRatio);
|
||||
}
|
||||
properties[(__bridge NSString *)kCGImageDestinationImageMaxPixelSize] = @(finalPixelSize);
|
||||
}
|
||||
|
|
|
@ -341,6 +341,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)test22ThatThumbnailPreserveAspectRatio {
|
||||
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImageLarge" ofType:@"jpg"];
|
||||
NSData *testImageData = [NSData dataWithContentsOfFile:testImagePath];
|
||||
CGSize thumbnailSize = CGSizeMake(400, 300);
|
||||
UIImage *image = [SDImageIOCoder.sharedCoder decodedImageWithData:testImageData options:@{
|
||||
SDImageCoderDecodePreserveAspectRatio: @(YES),
|
||||
SDImageCoderDecodeThumbnailPixelSize: @(thumbnailSize)}];
|
||||
CGSize imageSize = image.size;
|
||||
expect(imageSize.width).equal(400);
|
||||
expect(imageSize.height).equal(263);
|
||||
}
|
||||
|
||||
#pragma mark - Utils
|
||||
|
||||
- (void)verifyCoder:(id<SDImageCoder>)coder
|
||||
|
|
Loading…
Reference in New Issue