image-optimizer - php библиотека для сжатия и оптимизации изображений
Пример
$factory = new \ImageOptimizer\OptimizerFactory();
$optimizer = $factory->get();
$filepath = /* path to image */;
$optimizer->optimize($filepath);
//optimized file overwrites original one
https://github.com/psliwa/image-optimizer