Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save as indexed image #3

Open
basxto opened this issue Sep 10, 2019 · 11 comments
Open

Save as indexed image #3

basxto opened this issue Sep 10, 2019 · 11 comments
Labels
enhancement New feature or request

Comments

@basxto
Copy link

basxto commented Sep 10, 2019

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

@PureAsbestos
Copy link
Owner

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

@PureAsbestos
Copy link
Owner

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

@PureAsbestos PureAsbestos added enhancement New feature or request in progress This issue that is curently being worked on labels Sep 11, 2019
@PureAsbestos
Copy link
Owner

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

@PureAsbestos
Copy link
Owner

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

@PureAsbestos
Copy link
Owner

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

@PureAsbestos
Copy link
Owner

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

PureAsbestos added a commit that referenced this issue Sep 11, 2019
Also, some additional commentary
@PureAsbestos
Copy link
Owner

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

@basxto
Copy link
Author

basxto commented Sep 15, 2019

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
Copy link
Owner

PureAsbestos commented Sep 15, 2019

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 PureAsbestos removed the in progress This issue that is curently being worked on label Sep 15, 2019
@PureAsbestos PureAsbestos changed the title Save as paletted image Save as indexed image Sep 15, 2019
@basxto
Copy link
Author

basxto commented Sep 16, 2019

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants