Authored by Andrew Shu

Flag to transform animated images

Using a new SDWebImageOptions flag: SDWebImageTransformAnimatedImage
@@ -74,7 +74,14 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { @@ -74,7 +74,14 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
74 * By default, placeholder images are loaded while the image is loading. This flag will delay the loading 74 * By default, placeholder images are loaded while the image is loading. This flag will delay the loading
75 * of the placeholder image until after the image has finished loading. 75 * of the placeholder image until after the image has finished loading.
76 */ 76 */
77 - SDWebImageDelayPlaceholder = 1 << 9 77 + SDWebImageDelayPlaceholder = 1 << 9,
  78 +
  79 + /**
  80 + * We usually don't call transformDownloadedImage delegate method on animated images,
  81 + * as most transformation code would mangle it.
  82 + * Use this flag to transform them anyway.
  83 + */
  84 + SDWebImageTransformAnimatedImage = 1 << 10,
78 }; 85 };
79 86
80 typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); 87 typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
@@ -204,8 +204,7 @@ @@ -204,8 +204,7 @@
204 if (options & SDWebImageRefreshCached && image && !downloadedImage) { 204 if (options & SDWebImageRefreshCached && image && !downloadedImage) {
205 // Image refresh hit the NSURLCache cache, do not call the completion block 205 // Image refresh hit the NSURLCache cache, do not call the completion block
206 } 206 }
207 - // NOTE: We don't call transformDownloadedImage delegate method on animated images as most transformation code would mangle it  
208 - else if (downloadedImage && !downloadedImage.images && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) { 207 + else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) {
209 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 208 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
210 UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url]; 209 UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
211 210