Fix the encodeMaxPixelSize logic
Allows user to provide size which one dimension is larger than image size size Example - maxPixelSize: (200, 200), imageSize: (100, 400), result: (50, 200)
This commit is contained in:
parent
3746c5d4c6
commit
fcb53cb5ff
|
@ -499,7 +499,9 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
|||
CGFloat pixelWidth = (CGFloat)CGImageGetWidth(imageRef);
|
||||
CGFloat pixelHeight = (CGFloat)CGImageGetHeight(imageRef);
|
||||
CGFloat finalPixelSize = 0;
|
||||
if (maxPixelSize.width > 0 && maxPixelSize.height > 0 && pixelWidth > maxPixelSize.width && pixelHeight > maxPixelSize.height) {
|
||||
BOOL encodeFullImage = maxPixelSize.width == 0 || maxPixelSize.height == 0 || pixelWidth == 0 || pixelHeight == 0 || (pixelWidth <= maxPixelSize.width && pixelHeight <= maxPixelSize.height);
|
||||
if (!encodeFullImage) {
|
||||
// Thumbnail Encoding
|
||||
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
||||
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
|
||||
if (pixelRatio > maxPixelSizeRatio) {
|
||||
|
|
|
@ -252,10 +252,12 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
|||
}
|
||||
CGFloat pixelWidth = (CGFloat)CGImageGetWidth(imageRef);
|
||||
CGFloat pixelHeight = (CGFloat)CGImageGetHeight(imageRef);
|
||||
if (maxPixelSize.width > 0 && maxPixelSize.height > 0 && pixelWidth > maxPixelSize.width && pixelHeight > maxPixelSize.height) {
|
||||
CGFloat finalPixelSize = 0;
|
||||
BOOL encodeFullImage = maxPixelSize.width == 0 || maxPixelSize.height == 0 || pixelWidth == 0 || pixelHeight == 0 || (pixelWidth <= maxPixelSize.width && pixelHeight <= maxPixelSize.height);
|
||||
if (!encodeFullImage) {
|
||||
// Thumbnail Encoding
|
||||
CGFloat pixelRatio = pixelWidth / pixelHeight;
|
||||
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
|
||||
CGFloat finalPixelSize;
|
||||
if (pixelRatio > maxPixelSizeRatio) {
|
||||
finalPixelSize = MAX(maxPixelSize.width, maxPixelSize.width / pixelRatio);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue