Open basxto opened 5 years ago
Hi there! You can save your image as either PNG or BMP by adding the appropriate extension to the image before saving it.
Oh, I get what you are trying to say. Save it in "palette mode." I'll see what I can come up with.
Hmm... I seem to be able to get it to work right with PNG and mostly right with GIF, but BMP eludes me
GIF always gives a palette with 256 entries, I'm going to leave it at that
It works with PNG, so that will be included in the next update
If you find a way to do this for BMP in imageio, I'd be more than happy to implement it
PNGs will now be saved as paletted, see v3.2.3
It looks like it’s not possible, at least not how I had it in mind. The resulting PNG does not have palette defined in the GPL file, but an optimized variation of it.
Yeah, the palette gets reordered. I think the root problem is that there's no way to take a 2D array of integers and save it as an indexed image directly. Right now I have to convert from indexed to RGB, then when I save it I can have the image "quantized", but since I've already done that it ends up with the correct palette.
Pillow on the other hand has some methods that look interesting:
Image.convert(mode=None, matrix=None, dither=None, palette=0, colors=256)
Image.remap_palette(dest_map, source_palette=None)
https://pillow.readthedocs.io/en/stable/reference/Image.html
If Pillow is indeed capable of this functionality, perhaps an issue should be submitted to imageio to take advantage of it (seeing as it already relies on Pillow).
Saving images as 8bit PNG/BMP with given palette would make sense