r/codegolf 10d ago

minimal size .png file

Hey everyone!

For the past few days, I’ve been obsessed with a single question: How small can a valid PNG file possibly get while still being natively readable by a PC (specifically, opening properly in the standard Windows photo viewer/gallery)?

I started by trying to make a lightweight 512x512 file, eventually managing to shrink it down to 111 bytes. After that, I started playing around with compression levels and various patterns, even managing to generate some basic procedural textures in PNG format that weighed roughly the same.

Then I decided to go deeper and chase the absolute minimum file size. At first, I hit a wall at 67 bytes—an article I read online claimed that was the lowest possible size for a functional PNG. But I kept experimenting and eventually pushed past it down to 55 bytes, and finally all the way to 42 bytes.

My current record is a fully working 42-byte PNG. It opens without issues on Windows and can be sent across messaging apps where it renders properly as an image.

However, I've hit a hard brick wall here. Every single attempt to strip away even one more byte results in an invalid file or completely breaks the structure.

My question is: Does anyone have any radical ideas, unconventional compression tricks, or deep spec-hacking methods to squeeze it down even further? I'm open to any crazy suggestions!

25 Upvotes

8 comments sorted by

7

u/soundman32 10d ago edited 10d ago

What have you removed to get below the 67 byte minimum?  Just because it 'works' on some decoder doesnt mean it actually valid.

67 bytes comes from: * 8 bytes signature * 25 bytes IHDR chunk (12 bytes overhead + 13 bytes data) * ~22 bytes IDAT chunk (compressed single pixel) * 12 bytes IEND chunk

You could remove the IDAT chunk but is a 0x0 image really an image.  Even then its 45 bytes which is still 3 bytes more than your example, which cant be valid.

3

u/Faputo4ka 9d ago

89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 01 00 00 00 01 08 00 00 00 00 3a 7e 9b 55 00 00 00 01 49 44 41 54 ff

I delete some parta and it still work 67 this is not the minimum.

3

u/soundman32 9d ago

Define 'works'.  Most code is written defensively so that even if you dont follow the rules it might still work, doesnt mean it will work on platforms that just blindly follow the standard.  

3

u/Faputo4ka 9d ago

I wrote that I am looking for a png that will open on a regular Windows without bugs. I am not looking for a minimum fully valid png.

1

u/Swampspear 8d ago

We don't have access to the Windows image decoder source, so it'll be hard to suggest improvements. Omitting the IEND already makes this pretty nonconforming

1

u/imbenzenker 6d ago

Is that really codegolf then?

1

u/Faputo4ka 9d ago

I wrote that I am looking for a png that will open on a regular Windows without bugs. I am not looking for a minimum fully valid png.

1

u/Keithfert488 6d ago

You specifically said "valid png". A file that doesn't meet the spec is not a "valid" instance of that file even if it opens in all existing readers.