Image-palettizer icon indicating copy to clipboard operation
Image-palettizer copied to clipboard

Save as indexed image

Open basxto opened this issue 6 years ago • 11 comments

Saving images as 8bit PNG/BMP with given palette would make sense

basxto avatar Sep 10 '19 22:09 basxto

Hi there! You can save your image as either PNG or BMP by adding the appropriate extension to the image before saving it.

PureAsbestos avatar Sep 11 '19 03:09 PureAsbestos

Oh, I get what you are trying to say. Save it in "palette mode." I'll see what I can come up with.

PureAsbestos avatar Sep 11 '19 04:09 PureAsbestos

Hmm... I seem to be able to get it to work right with PNG and mostly right with GIF, but BMP eludes me

PureAsbestos avatar Sep 11 '19 04:09 PureAsbestos

GIF always gives a palette with 256 entries, I'm going to leave it at that

PureAsbestos avatar Sep 11 '19 04:09 PureAsbestos

It works with PNG, so that will be included in the next update

PureAsbestos avatar Sep 11 '19 04:09 PureAsbestos

If you find a way to do this for BMP in imageio, I'd be more than happy to implement it

PureAsbestos avatar Sep 11 '19 04:09 PureAsbestos

PNGs will now be saved as paletted, see v3.2.3

PureAsbestos avatar Sep 11 '19 05:09 PureAsbestos

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.

basxto avatar Sep 15 '19 14:09 basxto

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.

PureAsbestos avatar Sep 15 '19 19:09 PureAsbestos

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

basxto avatar Sep 16 '19 08:09 basxto

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).

PureAsbestos avatar Sep 16 '19 09:09 PureAsbestos