A Yii2 helper for optimizing image using spatie/image-optimizer library.
- Run the Composer command to install the latest version:
composer require rollingglory/yii2-image-optimizer
From here, you could either use it directly like this:
\rollingglory\ImageOptimizer\Optimizer::optimize('@app/image.png');
And like this:
use \rollingglory\ImageOptimizer\Optimizer;
Optimizer::optimize('@app/image.png');
Or, define it as Yii2 component. At your config:
'components' => [
'optimizer' => [
'class' => 'rollingglory\ImageOptimizer\Optimizer',
],
],
Then use it like this:
Yii::$app->optimizer::optimize('@app/image.png')