pngjs
pngjs copied to clipboard
Support writing indexed images
This patch adds support for writing indexed images with palettes. It also adds a new keepIndexed
option when reading files, so you can read an indexed image and keep the indexed data without it being converted to RGBA. This allows you to read, modify and write .png files while the data is in palette/index format the whole time. In this case it always unpacks the pixels when reading the file, so you end up with one pixel per byte, but e.g. in a 4-bit image with colours 0..3, each byte will always be < 4. The pixels are packed again when writing, so a 1-bit image will have eight pixels stored in a single byte.
The default for keepIndexed
is false
, so this change is backwards compatible and an indexed image will by default be converted to RGBA as is the case before this change.
Test code is included, and all the tests are passing except for a handful that were already failing before this change.
@lukeapage Any chance of getting this one merged? If not let me know and I will do a fork so I can use these changes in my other Node projects with a normal npm install
. Thanks!
@Malvineous do you want me to give you access to this repo and the npm package? or you would prefer just this merged (with the fork comment removed)
Thanks for the offer - I'm happy to help part-time with the maintenance of the project if you're willing to give me access!
I moved this to a org and invited you. Hopefully I will have a few hours later to set GitHub actions, upgrade deps and look at this pr etc.
Hello and thank you for this wonderful library! Is there any chance of a new release with this PR merged? I am in need for a way to write indexed images and would otherwise have to go with my own fork, since this and @Malvineous' fork have since diverged.