matthew-p/yii2-image-optimize

Very simple extension for optimize your folders with images or just images

Installs: 1 216

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 1

Open Issues: 0

Type:yii2-extension

1.0 2017-12-27 15:19 UTC

This package is auto-updated.

Last update: 2022-06-19 20:23:01 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');