From 30fd6cc6ab3d0bdad682bbb952dbca930f6391eb Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 21 Oct 2017 23:31:31 +0800 Subject: [PATCH] Implements -[NSImage isGIF] method to return whether current NSImage is GIF representation. --- SDWebImage/NSImage+WebCache.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SDWebImage/NSImage+WebCache.m b/SDWebImage/NSImage+WebCache.m index 518b498c..c5a3b8f5 100644 --- a/SDWebImage/NSImage+WebCache.m +++ b/SDWebImage/NSImage+WebCache.m @@ -23,7 +23,18 @@ } - (BOOL)isGIF { - return NO; + BOOL isGIF = NO; + for (NSImageRep *rep in self.representations) { + if ([rep isKindOfClass:[NSBitmapImageRep class]]) { + NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep; + NSUInteger frameCount = [[bitmapRep valueForProperty:NSImageFrameCount] unsignedIntegerValue]; + if (frameCount > 1) { + isGIF = YES; + break; + } + } + } + return isGIF; } @end