Update the test case to ensure the encoding options work

This commit is contained in:
DreamPiggy 2019-01-28 13:57:55 +08:00
parent df28feb99c
commit e303b7aed6
3 changed files with 11 additions and 2 deletions

View File

@ -208,7 +208,8 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
if (encodeFirstFrame || frames.count == 0) {
// for static single PNG images
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)properties);
CGImageRef imageRef = frames.firstObject.image.CGImage ?: image.CGImage;
CGImageDestinationAddImage(imageDestination, imageRef, (__bridge CFDictionaryRef)properties);
} else {
// for animated APNG images
NSUInteger loopCount = image.sd_imageLoopCount;

View File

@ -293,7 +293,8 @@
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
if (encodeFirstFrame || frames.count == 0) {
// for static single GIF images
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)properties);
CGImageRef imageRef = frames.firstObject.image.CGImage ?: image.CGImage;
CGImageDestinationAddImage(imageDestination, imageRef, (__bridge CFDictionaryRef)properties);
} else {
// for animated GIF images
NSUInteger loopCount = image.sd_imageLoopCount;

View File

@ -39,6 +39,12 @@
// Test image encode PNG
data = [image sd_imageDataAsFormat:SDImageFormatPNG];
expect(data).notTo.beNil();
// Test image encode JPEG with compressionQuality
NSData *jpegData1 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:1];
NSData *jpegData2 = [image sd_imageDataAsFormat:SDImageFormatJPEG compressionQuality:0.5];
expect(jpegData1).notTo.beNil();
expect(jpegData2).notTo.beNil();
expect(jpegData1.length).notTo.equal(jpegData2.length);
}
- (void)test03UIImageGIFCategory {
@ -49,6 +55,7 @@
NSData *data = [NSData dataWithContentsOfFile:[self testGIFPath]];
image = [UIImage sd_imageWithGIFData:data];
expect(image).notTo.beNil();
expect(image.sd_isAnimated).beTruthy();
}
#pragma mark - Helper