Skip to content
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.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.ico file may contain multiple images but only one is displayed #264

Open
karlcow opened this issue Jan 25, 2024 · 8 comments
Open

.ico file may contain multiple images but only one is displayed #264

karlcow opened this issue Jan 25, 2024 · 8 comments

Comments

@karlcow
Copy link
Member

karlcow commented Jan 25, 2024

ICO file format has the possibility to have multiple frames (different images) in one unique file.

  • Safari displays the first frame
  • Firefox/Chrome displays the last frame

This can create compatibility issues. There's at least one website where the first frame is transparent, and the favicon.ico image is in the last frame.

@karlcow
Copy link
Member Author

karlcow commented Jan 25, 2024

It is necessary to create a test favicon.ico image with different frames maybe a letter on each frame, so we can differentiate them.

@gsnedders
Copy link
Member

Note that, e.g., https://learn.microsoft.com/en-gb/previous-versions/ms997538(v=msdn.10) calls them images within an ICO file (or within an icon resource, but where an ICO file contains a single icon resource). We probably want something more like "the last image in the image directory in an ICO file".

"Frames" to me is much more reminiscent of animation (though there's a related question here—what happens if you use an APNG as an icon? or put an APNG as the last image in an ICO file?).

@miketaylr
Copy link
Member

Is WebKit willing to change its implementation to align with Gecko and Chromium? I guess we could spec out the Gecko and Chromium behavior either way...

@karlcow
Copy link
Member Author

karlcow commented Jan 25, 2024

It would be to have a test suite of ICO files, with different characteristics. Anyone from Microsoft who would know such a test suite?
A kind of a technical spec for it

@karlcow
Copy link
Member Author

karlcow commented Jan 25, 2024

@karlcow
Copy link
Member Author

karlcow commented Jan 25, 2024

@miketaylr do you know where is the algorithm for parsing favicon container in ICO for Chromium?

@karlcow karlcow changed the title .ico file may contain multiple frames but only one is displayed .ico file may contain multiple images but only one is displayed Jan 25, 2024
@karlcow
Copy link
Member Author

karlcow commented Jan 26, 2024

So the Firefox Algorithm goes (if I understood, please fix it if there is a mistake)

  1. Detect if animated or not
  2. If not animated
    1. get the sizes of all images
    2. if not empty and more than one image with size
      1. keep only images which are squares
      2. check if the size is compatible with what Gecko wants which is one of these 192, 144, 96, 64, 48, 32, 16
      3. Check if some sizes are duplicated to keep only the non duped
  3. Then pick the image with the largest side

There is an optimization done later on.

@miketaylr
Copy link
Member

miketaylr commented Jan 26, 2024

@miketaylr do you know where is the algorithm for parsing favicon container in ICO for Chromium?

https://source.chromium.org/chromium/chromium/src/+/main:ui/gfx/icon_util.h is probably a good place to start

(https://source.chromium.org/chromium/chromium/src/+/main:components/favicon/ is where the favicon component lives)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants