From a8c4fa48b796c583b06e77a40a2f6b3e66315d01 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Wed, 30 Apr 2014 14:05:37 -0700 Subject: [PATCH] Flag to transform animated images Using a new SDWebImageOptions flag: SDWebImageTransformAnimatedImage --- SDWebImage/SDWebImageManager.h | 9 ++++++++- SDWebImage/SDWebImageManager.m | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 6bb0dcfa..cae25d31 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -74,7 +74,14 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { * By default, placeholder images are loaded while the image is loading. This flag will delay the loading * of the placeholder image until after the image has finished loading. */ - SDWebImageDelayPlaceholder = 1 << 9 + SDWebImageDelayPlaceholder = 1 << 9, + + /** + * We usually don't call transformDownloadedImage delegate method on animated images, + * as most transformation code would mangle it. + * Use this flag to transform them anyway. + */ + SDWebImageTransformAnimatedImage = 1 << 10, }; typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 2781ec87..b8458b56 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -204,8 +204,7 @@ if (options & SDWebImageRefreshCached && image && !downloadedImage) { // Image refresh hit the NSURLCache cache, do not call the completion block } - // NOTE: We don't call transformDownloadedImage delegate method on animated images as most transformation code would mangle it - else if (downloadedImage && !downloadedImage.images && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) { + else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];