Yii2 extension for image manipulating using Kohana Image Library.

Installs: 118 209

Dependents: 19

Suggesters: 0

Stars: 61

Watchers: 15

Forks: 35

Open Issues: 1


v1.3 2019-01-25 01:01 UTC


Simple to use Yii2 Framework extension for image manipulating using powerful Kohana Image Library. Inspired by old yii extension http://www.yiiframework.com/extension/image/ and Kohana Image Library https://github.com/kohana/image


Install as a composer package

Use this method to get continuous updates.

composer require yurkinx/yii2-image

or include the dependency in the composer.json file:

    "require": {
        "yurkinx/yii2-image": "^1.2"


In config file


Add image component

'components' => array(
        'image' => array(
        	 	'class' => 'yii\image\ImageDriver',
        		'driver' => 'GD',  //GD or Imagick


header("Content-Type: image/png");
echo 	$image->resize($width,$height)->rotate(30)->render();

Supported methods out of the box from Kohana Image Library:

$image->resize($width = NULL, $height = NULL, $master = NULL);
$image->crop($width, $height, $offset_x = NULL, $offset_y = NULL);
$image->save($file = NULL, $quality = 100);
$image->render($type = NULL, $quality = 100);
$image->reflection($height = NULL, $opacity = 100, $fade_in = FALSE);
$image->background($color, $opacity = 100);
$image->watermark(Image $watermark, $offset_x = NULL, $offset_y = NULL, $opacity = 100);

Using resize with resize constrains

$image->resize($width, $height, \yii\image\drivers\Image::HEIGHT);
$image->resize($width, $height, \yii\image\drivers\Image::ADAPT)->background('#fff');

Using resize with resize constrains and best quality output image [for Imagick driver only]

Use 1 for best speed and lower quality, 100 for best quality and lower speed. Only values 1,100 currently supported

$image->resize($width, NULL, \yii\image\drivers\Image::WIDTH, 100);

Possible resize constrains:

// Resizing constraints ($master)
    const NONE    = 0x01;
    const WIDTH   = 0x02;
    const HEIGHT  = 0x03;
    const AUTO    = 0x04;
    const INVERSE = 0x05;
    const PRECISE = 0x06;
    const ADAPT   = 0x07;
    const CROP    = 0x08;

Using flip with flipping directions

// Flipping directions ($direction)

Possible flipping directions:

     const HORIZONTAL = 0x11;
     const VERTICAL   = 0x12;