SDWebImage: JPG image data is not visible with `SDAnimatedImage(data:)`/`AnimatedImage(data:)`(SwiftUI) while png data works fine

New Issue Checklist

Issue Info

Info Value
Platform Name iOS
Platform Version 15.0, 17.0
SDWebImage Version 5.18.3
Integration Method SPM
Xcode Version Xcode 15.0 / Xcode 15.1 Beta
Repro rate all the time (100%)
Repro with our demo prj not sure
Demo project link SDDisplayDemo.zip

Issue Description and Steps

Running demo project. JPG image data is not visible with SDAnimatedImage(data:)/AnimatedImage(data:)(SwiftUI) while png data works fine PS: I’m finding a common way to display image by data without local/remote url.

CleanShot 2023-10-20 at 17 29 47

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 25 (18 by maintainers)

Most upvoted comments

The behavior will not changes (at least in SDWebImage 5.x). If you init SDAnimatedImage failed, you MUST init UIImage and re-try again. This is why we Subclass UIImage

Even for UIKit code, you must do like this:

var image: UIImage? = SDAnimatedImage(data: data, scale: imageModel.scale)
if image == nil {
    // For static image, use UIImage as defaults
    image = UIImage(data: data)
}
sdaniamtedImageView.image = image

The behavior will not changes (at least in SDWebImage 5.x). If you init SDAnimatedImage failed, you MUST init UIImage and re-try again. This is why we Subclass UIImage

Even for UIKit code, you must do like this:

var image: UIImage? = SDAnimatedImage(data: data, scale: imageModel.scale)
if image == nil {
    // For static image, use UIImage as defaults
    image = UIImage(data: data)
}
sdaniamtedImageView.image = image

Oh…Seems this is not correct, compared to SDWebImage Core logic.

Should use this API instead:

var image: UIImage? = SDAnimatedImage(data: data)
if image == nil {
    // For static image, use UIImage as defaults
    image = UIImage.sd_image(with: data) // This API is from us and supports WebP/AVIF/PDF or other format Apple don't support
}
sdaniamtedImageView.image = image

I means, the release date of SDWebImage 5.19.0 may be delayed into next weak (2023-10-28)

Because there are some other changes (not related to this PR, but which deprecate some APIs so it need to bump minor versions…😂). I don’t want to release 5.19.0 today and another 5.20.0 next weak.

If you can’t wait to use this #3626, you can currently use the commit dependency (as you shown in screenshot) to test your project.