Skip to content

Any possible way to compress PNG or use indexed RGB on node-canvas? #332

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

Closed
hunt opened this issue Sep 13, 2013 · 7 comments
Closed

Any possible way to compress PNG or use indexed RGB on node-canvas? #332

hunt opened this issue Sep 13, 2013 · 7 comments

Comments

@hunt
Copy link

hunt commented Sep 13, 2013

I'm not sure is it possible or not? by node-canvas api after we use "createPNGStream" image will be in indexed rgb format or PNG-8

Thank you!

@kkoopa
Copy link
Contributor

kkoopa commented Jan 14, 2014

See #306

@hunt hunt closed this as completed Aug 26, 2015
@mathiasbynens
Copy link
Contributor

@kkoopa Could you clarify how #306 enables saving an indexed PNG8 file? It doesn’t seem like any of the filters map to that directly.

The only PNG8 example I see is using node-mapnik.

@kkoopa
Copy link
Contributor

kkoopa commented May 2, 2017

It does not enable indexed PNG8, just setting zlib compression level and filters.

@mathiasbynens
Copy link
Contributor

Thanks for clarifying, @kkoopa!

I guess this issue could be reopened and repurposed/renamed as “Make it possible to use PNG8 palette”, then.

@zbjornson
Copy link
Collaborator

@mathiasbynens FWIW, I've been starting to use this library with indexed PNG encoding by using one of the RGBA channels (e.g. A) as our palette indices, calling toBuffer("raw"), extracting and packing every 4th byte, and then using a different PNG encoding function to write the indexed PNG (we made our own; you can bind to libpng or lodepng for example).

I was toying with what an API in node-canvas could look like, e.g.

var c = new Canvas(w, h, "palette8" /* or "alpha8" or "png8" or ... */);
c.pngStream({palette: /* a Uint8ClampedArray of RGBA values */});

which seems all and well until you get to getImageData and putImageData -- if the returned pixel array is just one channel, it's compact and easy to work with but doesn't follow the Canvas specification; if it is unpacked and returns all four channels, it's bigger and harder to work with but follows the Canvas spec.

@zbjornson
Copy link
Collaborator

Actually, I just discovered PR #678, which lets you set any of Cairo's native formats (including alpha8). @mathiasbynens that would be a good place to discuss this further.

@LinusU
Copy link
Collaborator

LinusU commented May 3, 2017

Reopening this until we can get it resolved :)

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

No branches or pull requests

5 participants