From e665fb52d60c2c5fee1c99e70bbc48539eee8cb0 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 1 Jul 2024 18:21:01 +0800 Subject: [PATCH] Fix the issue that SDAnimatedImage breaks the vector on macOS --- SDWebImage/Core/SDAnimatedImage.h | 2 +- SDWebImage/Core/SDAnimatedImage.m | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SDWebImage/Core/SDAnimatedImage.h b/SDWebImage/Core/SDAnimatedImage.h index 78739c57..4f596997 100644 --- a/SDWebImage/Core/SDAnimatedImage.h +++ b/SDWebImage/Core/SDAnimatedImage.h @@ -72,7 +72,7 @@ // This class override these methods from UIImage(NSImage), and it supports NSSecureCoding. // You should use these methods to create a new animated image. Use other methods just call super instead. -// @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. +// @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. // @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. + (nullable instancetype)imageNamed:(nonnull NSString *)name; // Cache in memory, no Asset Catalog support #if __has_include() diff --git a/SDWebImage/Core/SDAnimatedImage.m b/SDWebImage/Core/SDAnimatedImage.m index e7467c47..56c63e1c 100644 --- a/SDWebImage/Core/SDAnimatedImage.m +++ b/SDWebImage/Core/SDAnimatedImage.m @@ -141,6 +141,12 @@ static CGFloat SDImageScaleFromPath(NSString *string) { if (!data || data.length == 0) { return nil; } + // Vector image does not supported, guard firstly + SDImageFormat format = [NSData sd_imageFormatForImageData:data]; + if (format == SDImageFormatSVG || format == SDImageFormatPDF) { + return nil; + } + id animatedCoder = nil; SDImageCoderMutableOptions *mutableCoderOptions; if (options != nil) { @@ -167,6 +173,10 @@ static CGFloat SDImageScaleFromPath(NSString *string) { if (!image) { return nil; } + // Vector image does not supported, guard secondly + if (image.sd_isVector) { + return nil; + } #if SD_MAC self = [super initWithCGImage:image.CGImage scale:MAX(scale, 1) orientation:kCGImagePropertyOrientationUp]; #else