use serhatozles\compressorio\CompressorIO;
$files = [];
$compress = new CompressorIO();
$compress->backup = true; // default: true. when it's true, create a directory and files will be copied to there before compressed.
$files[] = '/path/to/source/image/file.jpg';
$compress->compress($files);
// you can compress one file or get file list by a folder and compress.
$files = $compress->findFolder('png|jpg|jpeg|gif');
$compress->compress($files);
Simply add a dependency on serhatozles/compressor.io-php to your composer.json file if you use Composer to manage the dependencies of your project:
composer require serhatozles/compressor.io-php
Minify is MIT licensed.