matthew-p / yii2-image-optimize
Very simple extension for optimize your folders with images or just images
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 430
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
This package is auto-updated.
Last update: 2023-08-19 22:50:25 UTC
README
Very simple extension for optimize your folders with images or just images
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist matthew-p/yii2-image-optimize "*"
or add
"matthew-p/yii2-image-optimize": "*"
to the require section of your composer.json
file.
WARNING! Before use this extension, please visit ImageOptimizer and install optimizers from list in accordance with your OS.
Install optimizers in Ubuntu:
apt-get install -y libjpeg-progs && \ apt-get install -y jpegoptim && \ apt-get install -y pngquant
Usage
Once the extension is installed, simply use it in your code by:
FOR CONSOLE APPLICATION
In console main.php add:
return [ ... 'controllerMap' => [ ... 'image-optimize' => [ 'class' => ImageOptimizeController::class, 'log' => YII_DEBUG, 'imageExtensions' => [ ImageOptimizerService::IMAGE_PNG, ImageOptimizerService::IMAGE_JPG, ImageOptimizerService::IMAGE_JPEG, ], 'folders' => [ // Add your folders for images optimize '@frontend/web/uploads/test1', '@frontend/web/uploads/test2' => [ // with options 'execlude' => [ // Exclude subfolders or files '@frontend/web/uploads/test/subfolder', '@frontend/web/uploads/test/file.png', // Filename WITH PATH ] ], ], ], ... ] ... ];
And run in console:
php yii image-optimize
JUST USING THE EXTENSION
$optimizeService = new ImageOptimizerService(); // For folder $optimizeService->optimizeFolder('@frontend/web/uploads/test1'); // For image $optimizeService->optimizeFolder('@frontend/web/uploads/test1/image.png');