cliff363825/yii2-image

Image Component for Yii2

Installs: 3 137

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 6

Open Issues: 0

Type:yii2-extension

dev-master 2017-09-09 11:23 UTC

This package is auto-updated.

Last update: 2024-03-29 02:50:17 UTC


README

Image Component for Yii2

This extension is base on yii-easyImage, used for Yii2.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist cliff363825/yii2-image "*"

or add

"cliff363825/yii2-image": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply modify your application configuration as follows:

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:

// Create and autocache

Yii::$app->easyImage->thumbOf('/path/to/image.jpg', ['rotate' => 90]);

// or

Yii::$app->easyImage->thumbOf('image.jpg', ['rotate' => 90],  ['class' => 'image']);

// or

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()

####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.