Image Component for Yii2
Image Component for Yii2, (*1)
This extension is base on yii-easyImage, used for Yii2., (*2)
Installation
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require axelpal/yii2-easyImage
or add, (*5)
"axelpal/yii2-easyImage": "^1.0"
to the require section of your composer.json
file., (*6)
Usage
Once the extension is installed, simply modify your application configuration as follows:, (*7)
return [
...
'components' => [
....
'easyImage' => [
'class' => 'cliff363825\image\EasyImage',
'driver' => 'GD',
'quality' => 100,
'cachePath' => '/easyimage/',
'cacheTime' => 2592000,
'retinaSupport' => false,
'basePath' => '@webroot',
'baseUrl' => '@web',
]
],
];
Parameters
- string
$file
required - Image file path
- string
$driver
- Driver: GD
, Imagick
ThumbOf
You can create a thumbnail directly in the View
:, (*8)
// Create and autocache, (*9)
Yii::$app->easyImage->thumbOf('/path/to/image.jpg', ['rotate' => 90]);
// or, (*10)
Yii::$app->easyImage->thumbOf('image.jpg', ['rotate' => 90], ['class' => 'image']);
// or, (*11)
Yii::$app->easyImage->thumbOf('image.png', [
'resize' => ['width' => 100, 'height' => 100],
'rotate' => ['degrees' => 90],
'sharpen' => 50,
'background' => '#ffffff',
'type' => 'jpg',
'quality' => 60,
]);
Note. This method return Html::img(), (*12)
Parameters
- string
$file
required - Image file path
- array
$params
- Image manipulation methods. See Methods
- array
$htmlOptions
- options for Html::img()
For full details on usage, see the documentation., (*13)