@@ -262,8 +262,8 @@ - (void)verifyCoder:(id<SDImageCoder>)coder
262262 thumbnailPixelSize = CGSizeMake (round (thumbnailHeight * ratio), thumbnailHeight);
263263 }
264264 // Image/IO's thumbnail API does not always use round to preserve precision, we check ABS <= 1
265- expect (ABS (thumbImage.size .width - thumbnailPixelSize.width ) <= 1 );
266- expect (ABS (thumbImage.size .height - thumbnailPixelSize.height ) <= 1 );
265+ expect (ABS (thumbImage.size .width - thumbnailPixelSize.width )). beLessThanOrEqualTo ( 1 );
266+ expect (ABS (thumbImage.size .height - thumbnailPixelSize.height )). beLessThanOrEqualTo ( 1 );
267267
268268
269269 if (supportsEncoding) {
@@ -282,6 +282,25 @@ - (void)verifyCoder:(id<SDImageCoder>)coder
282282#if SD_UIKIT
283283 expect (outputImage.images .count ).to .equal (inputImage.images .count );
284284#endif
285+
286+ // check max pixel size encoding with scratch
287+ CGFloat maxWidth = 50 ;
288+ CGFloat maxHeight = 50 ;
289+ CGFloat maxRatio = maxWidth / maxHeight;
290+ CGSize maxPixelSize;
291+ if (ratio > maxRatio) {
292+ maxPixelSize = CGSizeMake (maxWidth, round (maxWidth / ratio));
293+ } else {
294+ maxPixelSize = CGSizeMake (round (maxHeight * ratio), maxHeight);
295+ }
296+ NSData *outputMaxImageData = [coder encodedDataWithImage: inputImage format: encodingFormat options: @{SDImageCoderEncodeMaxPixelSize : @(CGSizeMake (maxWidth, maxHeight))}];
297+ UIImage *outputMaxImage = [coder decodedImageWithData: outputMaxImageData options: nil ];
298+ // Image/IO's thumbnail API does not always use round to preserve precision, we check ABS <= 1
299+ expect (ABS (outputMaxImage.size .width - maxPixelSize.width )).beLessThanOrEqualTo (1 );
300+ expect (ABS (outputMaxImage.size .height - maxPixelSize.height )).beLessThanOrEqualTo (1 );
301+ #if SD_UIKIT
302+ expect (outputMaxImage.images .count ).to .equal (inputImage.images .count );
303+ #endif
285304 }
286305}
287306
0 commit comments