siiptuo / pio

Optimize images while maintaining the same perceived quality
138 stars 10 forks source link

Prevent compressing images that are too low quality #16

Open joppuyo opened 3 years ago

joppuyo commented 3 years ago

As noted in the readme

The input image should preferably be PNG or lossless WebP, or alternatively JPEG or lossy WebP stored with a high-quality setting (95-100). pio will make already lossy compressed images look worse.

It could be useful if pio could automatically estimate the quality and if it falls below target quality, prevent double compressing the image. Something like this or this could be used to estimate the quality.

Image quality target could also be scaled depending on the compression of the original. For example, if the original image quality is lossless/100 and the target is 80, compression would be applied normally. But if the original image quality is 90 and the target is 80, less compression would be applied to keep the end result similar and not degraded because the original image quality is lower.

This needs some testing. I think in some extreme cases double compression is avoided because the file size of the double compressed image would be larger than the original.

joppuyo commented 3 years ago

I did some testing with the command identify -verbose image.jpg | grep -i quality and the quality differs wildly from the quality set in Photoshop or cjpeg so I don't think it's very reliable.