I have a tileset generator. It grabs all unique tiles from an image and makes a new PNG out of them. You know how tilesets work.
I tried homebrewing a compressor/decompressor algorithm that mimicked the NES's 2-bits-per-pixel method. Lots of bit-packing. Every two bits indexes a color in that sprite's palette.
I saw some success with my algorithm when a 16-by-16px sprite was 1) only two colors and 2) symmetrical both horizontally and vertically. It turned such a 227-byte PNG into 8 bytes! It could then decompress it in a millisecond, which seems slow for such a small image. But I'll accept it.
But when I used 7 colors and needed 4 bpp, the compressed image would be larger than the original.
So then I tried just using PyPNG. It takes the same 227-byte, two-color image I mentioned before and compresses it to 81 bytes. That seems wrong.
But the same PyPNG method does turn my attached, 7-color michael.png (548 bytes) into michael_output.png (327 bytes). Code snippet's below:
w = final_tileset.shape[1]
h = final_tileset.shape[0]
writer = png.Writer(w, h, bitdepth=bitdepth, palette=color_palette) #bitdepth is 4 in this case, and palette has 7 RGB vals.
output_file = open("michael_output.png", "wb")
writer.write(output_file, final_tileset_iterable)
Seems like I could still squeeze it even smaller somehow. I'm sure you seasoned pros have a few tricks up your sleeves for this. How small can I possibly make this particular attached image?