The smallest PNG file is 67 bytes. It’s a single black pixel. Here’s what it looks like, zoomed in 200×:
[…]The rest of this post describes this file in more detail and tries to explain how PNGs work along the way.
There’s a big twist at the end, if that excites you. But I hope you’re just excited to learn about PNGs.
↫ Evan Hahn
I know way too much about PNGs now, information I won’t ever need but am glad to have.
Greetings!
This is a big opportunity to shout out for two amazing SSE/AVX optimized encoders:
SSE FPNG: https://github.com/richgel999/fpng
AVX FPNGe: https://github.com/veluca93/fpnge
Java Wrapper: https://github.com/manticore-projects/fpng-java
Benchmarks: https://github.com/manticore-projects/fpng-java/blob/main/src/site/sphinx/_static/benchmark_small.svg
For the curious – here is a repository of smallest syntactically valid files of various file types: https://github.com/mathiasbynens/small
PNG at 67B seems like a pig compared to 16B that JPEG XL needs 🙂
Quikee,
Well duh, the jpeg is lossy 🙂
j/k
I actually tried to get gimp to produce a 0x0 png, but it couldn’t handle it. Never-the-less I would think that a zero pixel png is still syntactically valid? If so, then arguably the author is mistaken, even smaller valid PNG files could exist. When I was reading the article, I thought this was going to be the “twist”.
Alfman,
I’m not sure “0 pixels” is valid. (I have not been able to find example, but I can’t rule that black swan out).
That being said, there is a nice, illustrated example at Wikipedia:
https://en.wikipedia.org/wiki/PNG#Examples
It seems like the only place they can cut is the actual (compressed) pixel data. And it is 6 bytes (adding to a 69 bytes total file size).
Whereas the example in the article is only 4 bytes (the other one is RED so there is more entropy to encode with the compression algorithm, this one is pure black).
sukru,
Well, it is mathematically valid – the set of all images contains one with zero pixels in the same sense that the set of all strings contains a string with zero characters. But I took a look at the png specs and here’s what it says…
https://www.w3.org/TR/png-3/
So per the spec, it is invalid to have a png file representing an image with a width or height of zero. So 1×1 is the smallest valid PNG size.
Using libpng the arbitrary grayscale colors I tested all produced a 67 byte file.
Alfman,
Thank you for getting a definite answer.
Interesting. Then maybe gray encodes better with that compression algorithm (deflate?) than a single primary color?
Anyway, clearly this is the limit, and I might have made some design decisions to make it smaller, but that requires dusting off my time machine.
According to your list smallest valid PNG is 51 bytes.
I think 51 bytes is the “invalid” one where they removed some required data fields. But given most software is “permissive” it might load after all.
That was a wonderful read. 🙂
I’ve always loved learning about file types. Image, audio, video, and compression formats are so much fun to learn about. Filesystems also scratch the same itch.
Yeah agreed! It has given me a strange urge to write a PNG viewer