I'm wondering how to figure out the best compress rate (small filesize + no quality loss) automatically.
At the moment I'm using imagejpeg() with $quality = 85
for each .jpg
.
PageSpeed (Chrome Plugin) suggests, to lower the quality of a few images to save some kb. The percentage of reduction is different.
I'd like to write a cronjob that crawls a specific directory and optimizes every image.
How does PageSpeed or TinyPNG figure out the best optimized quality and is this possible with PHP or another serverside-language?