daxslab / yii2-thumbnailer
Yii2 component to generate image thumnails of any size
Installs: 13 800
Dependents: 1
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 4
Open Issues: 2
Type:yii2-extension
Requires
- yiisoft/yii2: *
- yiisoft/yii2-imagine: ~2.2.0
README
Yii2 component to generate image thumnails of any size.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist daxslab/yii2-thumbnailer "*"
or add
"daxslab/yii2-thumbnailer": "*"
to the require section of your composer.json
file.
Configuration
The basic configuration only requires adding the component to the application:
'components' => [ //... 'thumbnailer' => [ 'class' => 'daxslab\thumbnailer\Thumbnailer', ], //... ]
Besides that a default value is always provided, all the options can be configured.
'components' => [ //... 'thumbnailer' => [ 'class' => 'daxslab\thumbnailer\Thumbnailer', 'defaultWidth' => 500, 'defaultHeight' => 500, 'thumbnailsBasePath' => '@webroot/assets/thumbs', 'thumbnailsBaseUrl' => '@web/assets/thumbs', 'enableCaching' => true, //defaults to false but is recommended ], //... ]
Usage
Once the extension is configured, simply use it in your views by:
//Generates thumbnail with default values specified in the configuration Html::img(Yii::$app->thumbnailer->get($imageUrl)); //Generates a 400px width thumbnail. The height is determined as the width because is not set. Html::img(Yii::$app->thumbnailer->get($imageUrl, 400)); //Generates a 400x400 pixels thumbnail and 60% quality Html::img(Yii::$app->thumbnailer->get($imageUrl, 400, 400)); //Generates a 400x400 pixels thumbnail and 10% quality Html::img(Yii::$app->thumbnailer->get($imageUrl, 400, 400, 10)); //Generates a 400x400 pixels thumbnail, 10% quality and not cropping the image //but inserting it into a box with the specified dimensions. Html::img(Yii::$app->thumbnailer->get($imageUrl, 400, 400, 10, ManipulatorInterface::THUMBNAIL_INSET));
Proudly made by Daxslab.