1. Go to this page and download the library: Download ps/image-optimizer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ps / image-optimizer example snippets
$factory = new \ImageOptimizer\OptimizerFactory();
$optimizer = $factory->get();
$filepath = /* path to image */;
$optimizer->optimize($filepath);
//optimized file overwrites original one
$factory = new \ImageOptimizer\OptimizerFactory(array('ignore_errors' => false), $logger);
//default optimizer is `smart`
$optimizer = $factory->get();
//png optimizer
$pngOptimizer = $factory->get('png');
//jpegoptim optimizer etc.
$jpgOptimizer = $factory->get('jpegoptim');
class StdoutLogger extends \Psr\Log\AbstractLogger {
public function log($level, $message, array $context = array()) {
echo $message."\n";
}
}
$factory = new \ImageOptimizer\OptimizerFactory(array(), new StdoutLogger());
$factory->get()->optimize('yourfile.jpg');
// and have a look at stdout
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.