Skip to content

Commit e665fb5

Browse files
committed
Fix the issue that SDAnimatedImage breaks the vector on macOS
1 parent b8523c1 commit e665fb5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

SDWebImage/Core/SDAnimatedImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
// This class override these methods from UIImage(NSImage), and it supports NSSecureCoding.
7474
// You should use these methods to create a new animated image. Use other methods just call super instead.
75-
// @note Before 5.19, these initializer will return nil for static image (when all candidate SDAnimatedImageCoder returns nil instance), like JPEG data. After 5.19, these initializer will retry for static image as well, so JPEG data will return non-nil instance.
75+
// @note Before 5.19, these initializer will return nil for static image (when all candidate SDAnimatedImageCoder returns nil instance), like JPEG data. After 5.19, these initializer will retry for static image as well, so JPEG data will return non-nil instance. For vector image(PDF/SVG), always return nil.
7676
// @note When the animated image frame count <= 1, all the `SDAnimatedImageProvider` protocol methods will return nil or 0 value, you'd better check the frame count before usage and keep fallback.
7777
+ (nullable instancetype)imageNamed:(nonnull NSString *)name; // Cache in memory, no Asset Catalog support
7878
#if __has_include(<UIKit/UITraitCollection.h>)

SDWebImage/Core/SDAnimatedImage.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ - (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale options:(SDImag
141141
if (!data || data.length == 0) {
142142
return nil;
143143
}
144+
// Vector image does not supported, guard firstly
145+
SDImageFormat format = [NSData sd_imageFormatForImageData:data];
146+
if (format == SDImageFormatSVG || format == SDImageFormatPDF) {
147+
return nil;
148+
}
149+
144150
id<SDAnimatedImageCoder> animatedCoder = nil;
145151
SDImageCoderMutableOptions *mutableCoderOptions;
146152
if (options != nil) {
@@ -167,6 +173,10 @@ - (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale options:(SDImag
167173
if (!image) {
168174
return nil;
169175
}
176+
// Vector image does not supported, guard secondly
177+
if (image.sd_isVector) {
178+
return nil;
179+
}
170180
#if SD_MAC
171181
self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:kCGImagePropertyOrientationUp];
172182
#else

0 commit comments

Comments
 (0)