PureAsbestos / Image-palettizer

A program that applies a .gpl palette to an image.
MIT License
29 stars 3 forks source link

Save as indexed image #3

Open basxto opened 5 years ago

basxto commented 5 years ago

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

PureAsbestos commented 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.

PureAsbestos commented 5 years ago

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

PureAsbestos commented 5 years ago

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

PureAsbestos commented 5 years ago

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

PureAsbestos commented 5 years ago

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

PureAsbestos commented 5 years ago

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

PureAsbestos commented 5 years ago

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

basxto commented 5 years ago

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.

PureAsbestos commented 5 years ago

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.

basxto commented 5 years ago

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

PureAsbestos commented 5 years ago

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