GeezerVison is showing github.com — Added support to encode APNG instead of GIF, when no animated image format provided by dreampiggy · Pull Request #3867 · SDWebImage/SDWebImage
Added support to encode APNG instead of GIF, when no animated image format provided
#3867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Potential issue | 🟡 Minor
Stale comment on Line 277.
The comment still reads "use GIF (APNG may be better, but has bugs before macOS 10.14)" but the code now conditionally uses PNG/APNG on newer OS versions. Update the comment to reflect the new behavior.
📝 Suggested comment update
- // If image is animated, use GIF (APNG may be better, but has bugs before macOS 10.14)+ // If image is animated, prefer APNG on newer OS versions for better quality; fall back to GIF on older OS versions (APNG has bugs before macOS 10.14)
📝 Committable suggestion
‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change
if (format == SDImageFormatUndefined) {
// If image is animated, use GIF (APNG may be better, but has bugs before macOS 10.14)
In `@SDWebImage/Core/SDImageCache.m` around lines 276 - 283, Update the stale
comment near the SDImageFormatUndefined check to reflect the conditional choice
of PNG/APNG on newer OSes: mention that if image.sd_imageFrameCount > 1 the code
uses PNG (APNG on supported OS versions) when available and falls back to GIF on
older OSes (SDImageFormatPNG vs SDImageFormatGIF), so modify the comment to
describe that behavior instead of saying "use GIF (APNG may be better...)".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
All reactions
} else {
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
format = [SDImageCoderHelper CGImageContainsAlpha:image.CGImage] ? SDImageFormatPNG : SDImageFormatJPEG;
For UIKit, this will apply the patch and then create animated UIImage. The patch is because that `+[UIImage animatedImageWithImages:duration:]` just use the average of duration for each image. So it will not work if different frame has different duration. Therefore we repeat the specify frame for specify times to let it work.
For AppKit, NSImage does not support animates other than GIF. This will try to encode the frames to GIF format and then create an animated NSImage for rendering. Attention the animated image may loss some detail if the input frames contain full alpha channel because GIF only supports 1 bit alpha channel. (For 1 pixel, either transparent or not)
For AppKit before macOS 10.13, NSImage does not support animates other than GIF. This will try to encode the frames to GIF format and then create an animated NSImage for rendering. Attention the animated image may loss some detail if the input frames contain full alpha channel because GIF only supports 1 bit alpha channel. (For 1 pixel, either transparent or not)
For AppKit after macOS 10.14, use APNG format, which has a better render result.
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Potential issue | 🟡 Minor
Documentation gap for macOS 10.13.
The doc says "before macOS 10.13" uses GIF and "after macOS 10.14" uses APNG, but says nothing about macOS 10.13 itself. Since the @available check in the implementation uses macOS 10.14, macOS 10.13 falls into the GIF path. Consider rewording to "before macOS 10.14" for clarity and consistency with the implementation.
📝 Suggested doc fix
- For AppKit before macOS 10.13, NSImage does not support animates other than GIF. This will try to encode the frames to GIF format and then create an animated NSImage for rendering. Attention the animated image may loss some detail if the input frames contain full alpha channel because GIF only supports 1 bit alpha channel. (For 1 pixel, either transparent or not)- For AppKit after macOS 10.14, use APNG format, which has a better render result.+ For AppKit before macOS 10.14, NSImage does not support animates other than GIF. This will try to encode the frames to GIF format and then create an animated NSImage for rendering. Attention the animated image may loss some detail if the input frames contain full alpha channel because GIF only supports 1 bit alpha channel. (For 1 pixel, either transparent or not)+ For AppKit on macOS 10.14+, use APNG format, which has a better render result.
🤖 Prompt for AI Agents
In `@SDWebImage/Core/SDImageCoderHelper.h` around lines 71 - 72, Update the doc
comment in SDImageCoderHelper.h to match the implementation's availability
check: change the "before macOS 10.13" phrasing to "before macOS 10.14" (or
rephrase to "macOS prior to 10.14") and indicate that APNG is used on macOS
10.14 and later so macOS 10.13 is clearly included in the GIF path; edit the
comment block around the NSImage/animate description to use "before macOS 10.14"
and "macOS 10.14 and later" to align with the `@available`(macOS 10.14, *) check
in the implementation.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
All reactions
@param frames The frames array. If no frames or frames is empty, return nil
@return A animated image for rendering on UIImageView(UIKit) or NSImageView(AppKit)
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.