pngquant icon indicating copy to clipboard operation
pngquant copied to clipboard

how to avoid compress same png multi times

Open ruidge opened this issue 3 years ago • 6 comments

I write a script to compress all png in the project. the command is ' pngquant --skip-if-larger --speed 1 --nofs --strip --force --output "xx.png" -- "xx.png" '. It works well in 1st time compress, but the script still compress some png in 2nd, 3rd time . I compare the result the 2nd or 3rd compress just reduce 0.0x kb or 0.x kb size. What can I do to avoid these compress.(avoid compress same png multi times ). custom command args or record png name myself or other graceful?

ruidge avatar Mar 29 '21 02:03 ruidge

I write a script to compress all png in the project. the command is ' pngquant --skip-if-larger --speed 1 --nofs --strip --force --output "xx.png" -- "xx.png" '. It works well in 1st time compress, but the script still compress some png in 2nd, 3rd time . I compare the result the 2nd or 3rd compress just reduce 0.0x kb or 0.x kb size. What can I do to avoid these compress.(avoid compress same png multi times ). custom command args or record png name myself or other graceful?

I use ImageMagick to see png's metadata and compare the compressed and origin meta, and list some diff: change Type (TrueColorAlpha -> PaletteAlpha); change Red ,Green, Blue's min ,add Histogram ; then I update the script, read the meta before compress , only compress when Type != PaletteAlpha, is this fine?

ruidge avatar Mar 29 '21 08:03 ruidge

You can skip PNG files that have type PaletteAlpha.

Or you don't have to do anything — if you don't use quality setting, then pngquant won't do anything to such files.

kornelski avatar Mar 29 '21 10:03 kornelski

You can skip PNG files that have type PaletteAlpha.

Or you don't have to do anything — if you don't use quality setting, then pngquant won't do anything to such files.

so what cause 0.0x kb or 0.x kb's reduce and what is --quality default value(s)?

ruidge avatar Mar 30 '21 01:03 ruidge

quality default is 0-100, which means it does as good as it can, accepts any result. for png8 it always achieves 100%.

small reduction can be due to lossless recompression.

kornelski avatar Mar 30 '21 14:03 kornelski

quality default is 0-100, which means it does as good as it can, accepts any result. for png8 it always achieves 100%.

small reduction can be due to lossless recompression.

If so, I may compress all png every time. by the way, how about pngquant compatibility on mobile devices, Android, iOS, web on chrome ?

ruidge avatar Mar 31 '21 01:03 ruidge

PNG written by pngquant are standard and work on all platforms.

kornelski avatar Mar 31 '21 08:03 kornelski