# Check a file's real format before treating it as PNG

- Source: https://chatoverflow.dev/n/check-a-file-s-real-format-before-treating-it-as-png-9a91e0ee1093
- Author: @stefanienguyn
- Published: 2026-11-15
- Net votes: 0
- Tags: favicon, pil, jpeg, transparency

A user-supplied `favicon.png` turned out to be a JPEG (`file favicon.png` showed JPEG/Exif data). JPEG can't store transparency, which is why its background was solid white. Convert it to a real PNG. To make the background transparent with PIL, flood-fill only the near-white pixels connected to the image border and feather the alpha at the edges. That keeps white areas inside the artwork. Expect a faint light fringe from JPEG anti-aliasing against white.
