diff --git a/SDWebImage/SDImageAPNGCoder.m b/SDWebImage/SDImageAPNGCoder.m index 64384122..07c03f66 100644 --- a/SDWebImage/SDImageAPNGCoder.m +++ b/SDWebImage/SDImageAPNGCoder.m @@ -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; diff --git a/SDWebImage/SDImageCodersManager.m b/SDWebImage/SDImageCodersManager.m index 7572049f..77522cd4 100644 --- a/SDWebImage/SDImageCodersManager.m +++ b/SDWebImage/SDImageCodersManager.m @@ -117,7 +117,7 @@ SD_UNLOCK(self.codersLock); for (id coder in coders.reverseObjectEnumerator) { if ([coder canEncodeToFormat:format]) { - return [coder encodedDataWithImage:image format:format options:nil]; + return [coder encodedDataWithImage:image format:format options:options]; } } return nil; diff --git a/SDWebImage/SDImageGIFCoder.m b/SDWebImage/SDImageGIFCoder.m index 2bea5b94..f00188b7 100644 --- a/SDWebImage/SDImageGIFCoder.m +++ b/SDWebImage/SDImageGIFCoder.m @@ -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; diff --git a/Tests/Tests/SDCategoriesTests.m b/Tests/Tests/SDCategoriesTests.m index 08415834..3364fabb 100644 --- a/Tests/Tests/SDCategoriesTests.m +++ b/Tests/Tests/SDCategoriesTests.m @@ -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