Forum archive
Crunching a small PNG by a few more bytes
- I've got a 515 byte PNG that I'd like to reduce by four bytes to make it <0.5kB. The image in question contains around 100 different characters from the TI-85 character set. I have rearranged the characters in the image (which is 1 bit/pixel) to improve the compression and managed to reduce the size by 10 to 20 bytes already. Does anyone have any ideas on how to reduce the size of the file by a few more bytes? Any thoughts on how the characters should be rearranged to further improve the compression?
The file can be found here:
http://www.iki.fi/jterho/3a/matopeli/ti-85-merkit.png
I'm using the PNG in question in a JavaScript simulation of a TI-85 "worm" game that I made ten years ago when I was in high school. The game which uses the PNG can be found here:
http://www.iki.fi/jterho/3a/matopeli/mato-javascript.html
(Unfortunately, that page is in my native Finnish, but you can still play the game by pressing Enter/Return at the beginning. Use the arrow keys (preferably numeric keypad with NumLock on) to play. Steer the worm against its current direction to activate "reverse" which flips the entire worm around.)
To simplify the HTML, I would like to avoid removing the 1px vertical space between the characters in the PNG. However, I'd appreciate any other ideas on how to reduce the file to a size of under 512 bytes. - If you pipe it through pngrewrite and then pngout /f0, it drops to 497 bytes. This makes it a 1 bit grayscale, rather than 1 bit paletted, which drops the palette completely, losing 18 bytes.
Mark - You could also run "pngout /f0 /c0" to get the 497 byte image in one step. I noticed your font is actually 6x8 with pixels duplicated. With some fiddling, I got it down to 453 bytes. After loading, you'll need to duplicate pixels and then turn the characters sideways. I don't feel like hosting the file, and I didn't have much luck with UUENCODE, so here's the 453 byte image in hex:
89504E470D0A1A0A0000000D49484452000003100000000601000000007BE545
4B0000018C49444154785EB591B18A14411086AFD8407C06837D0263111111F1
11E4A2C1C0C0E0681A3926389666581A31321A0E035916E3C3500E598EA19960
23D9A8690E2986A1830D8EA59061198EA668BB6F51F001FCC2E22F3E7EFEA398
09DEACDB167B3261DBFBBE27C8C70651AFB47EFF65FE61B9A8EBE154554F9917
A755CC10C1E4DE64FA580154A6EF7B3FBC716E7CD67CD71F97977B172965548C
E80F0AC41078FFC3BAADB51D765DB7637EC1D5CDCD37A5D44CC813792232B260
160F2BA5222705716072ABB1997CFE74FCAA10850378DD5D17425E0422B74EBF
D368F1280E757D8BC83CECAD75CEDA6D56203C4794E39815A59042BE3D280473
5940E6BE2662F6BFC8D14615C7CEE2AE70EE52128997259CEB7A95A8E3342BF6
E7778AD4E2FA4ED1ED880815F2640EA9452629A4105F93A2643E53958AEAEA6F
0BEA1A5EFC69E1DE8D8F4A555D084A6F6B47D368CC610BEFDB75BBC16068E70D
80313EC6D051C48D06ADF57C090075BB003803BE9AFDBB050084345FF0C303E7
B65578A275F3B3762A47722E6DF1DFF90D80B2AFDE4400782B0000000049454E
44AE426082
Happy reconstructing! : P - The agony of choice:
Upload the unhexed version to imageshack,
or let people have their fun?
.....
.....
Oh, what the heck.
http://img203.exs.cx/img203/771/hexpng1mw.png
(The image is a bit too wide for the forum, so I'll just give the link instead)Edited at Nice job
Ken's version is pretty nifty. However, I specifically need a PNG where the characters are NOT rotated, where the pixels are duplicated (as in my original version), where the image begins with a "space" character and where the last two characters remain the same as in the original.
I initially thought about writing something that would rearrange the characters and check how well different arrangements can be compressed, but there are a gazillion different permutations (type "95 factorial" into Google to find out how many). I guess you'd have to come up with some sort of a strategy to try specific types of character arrangements so that you could maximize the likelihood of finding the ones that give you the best level of compression.
However, I really don't know that much about compression algorithms so I don't know what kind of an approach you should employ. When I rearranged the characters manually, I just tried to place similar-looking characters next to each other, which gave me a reduction 10 or 20 bytes, as I mentioned earlier.
In any case, the 497-byte file is the one I'll be using, unless someone comes up with a way to compress the image even further - within the constraints that I have put forward here (begin with a space, no rotating, etc). Thanks a lot. ("Reconstructing" the PNG from the hex version wasn't that cumbersome... in fact, using hex is a pretty nice way of distributing small files in a text format.)Clarification
I wrote the previous post in a real hurry, so I'd just want to clarify a thing or two. I meant to say that I was thinking of writing a script of some sort that would reorder the characters in the image and would then feed the results to PNGOUT to find out which arrangement of characters yields the highest level of compression. However, I'm perfectly happy with the 497-byte version. I'm not sure whether those two points I was trying to make came across in my post above. Anyway, thanks once more for the advice.Crunching a small PNG by a few more bytes
It is only me or is it not so that compression works finer wenn picture is mor square shaped?