I'm looking for a library or algorithm that will make a bitmap as small as it can be without losing information. For instance, given a 600x400 solid black image, I want to get a 3x2 solid black image.
My use case: I have a database of flag images that I want to optimize. Many flags, like France and Italy, are made out of blocks of solid color, so the pngs can be much smaller than the high resolution I use for detailed flags like Spain. I generate the png database by exporting an often-updated database of flag SVGs ripped from Wikimedia. I want to integrate the described lossless resizing into the export pipeline.
I've tried to find this information online, but I'm not really sure how to describe my problem with a few keywords. I keep finding stuff about lossless compression, which is different from lossless resizing.
I have ended up calculating this manually for flags where it's relevant, and including that information in my flag database. Most flag SVGs get exported at the requested maximum resolution, but if they have a supplied minimum resolution without data loss
that is lower, they get exported at that. So for instance, my database now contains minimum resolution without data loss
of 3x2 for France and 5x3 for Germany.