lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.13k stars 1.3k forks source link

the output png will lost Colors #2763

Closed finscn closed 2 years ago

finscn commented 3 years ago

Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?

yes , I've tried from 0.27 to 0.28.3.

What are the steps to reproduce? Use sharp output png whatever how to set options. image

What is the expected behaviour? the output file should not lost the colors.

original image: image

output image: image

see the red spots in the sail. There are many pixel lost color


What is the output of running npx envinfo --binaries --system? System: OS: macOS 11.4 CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz Memory: 109.24 MB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 12.22.1 - ~/.nvm/versions/node/v12.22.1/bin/node Yarn: 1.22.10 - ~/.nvm/versions/node/v12.22.1/bin/yarn npm: 7.15.0 - ~/.nvm/versions/node/v12.22.1/bin/npm

finscn commented 3 years ago

In the options , I've tried set false or true to palette , compressionLevel = 0 to 9 , no effect to save full color.

lovell commented 3 years ago

Please can you provide input images and the complete, standalone code (as text, not an image) that allows someone else to reproduce this.

finscn commented 3 years ago

test-bug.zip

npm install

node main.js

see the the difference between input/3-bug-image.png and the part of output.png

image

finscn commented 3 years ago

I know composite by a batch of images is better than composite image one by one. But I think the composite().toBuffer() should be lossless compression. So even I composite one by one , the result should as same as composite by a batch of images.

lovell commented 3 years ago

The input image 3-bug-image.png has an alpha channel and a "background" (matte) of #BDBDBD00. When you view the image on its own, e.g. in a browser, the background colour will appear under the image. When you composite, the background colour is ignored as you are providing the background to composite over.

If you'd like to include the background colour of an image when compositing, you'll need to composite that image over a solid image of the background colour first.

At the moment sharp doesn't expose the background colour of a PNG (this is the bKGD chunk) although it would make a good addition.

finscn commented 3 years ago

@lovell , but if I composite all images in an array (just run composite() one time ) , not one by one, there is no any issue.

So maybe there is some misunderstanding

finscn commented 3 years ago

@lovell , There is a new test-case : test-sharp-bug.zip

you could compare the two js-files.

lovell commented 2 years ago

Please can you try with the latest v0.30.3 release, as there have been a number of recent improvements to the speed and accuracy of composite.

https://sharp.pixelplumbing.com/changelog

lovell commented 2 years ago

I hope this information helped. Please feel free to re-open with more details if further assistance is required.