coderfly/yii2-image

This package is abandoned and no longer maintained. No replacement package was suggested.

Yii2 extension for image manipulating using Kohana Image Library by Yuri Kileev.

Installs: 437

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 24

Type:yii2-extension

dev-master 2014-10-06 15:24 UTC

This package is not auto-updated.

Last update: 2016-03-04 13:01:42 UTC


README

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

Installation

{
    "require": 
    {
        "yurkinx/yii2-image": "dev-master"
    }
}

Configuration

In config file

/config/web.php

Add image component

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

Usage

$file=Yii::getAlias('@app/pass/to/file'); 
$image=Yii::$app->image->load($file);
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->sharpen($amount);
$image->rotate($degrees);
$image->save($file = NULL, $quality = 100);
$image->render($type = NULL, $quality = 100);
$image->reflection($height = NULL, $opacity = 100, $fade_in = FALSE);
$image->flip($direction);
$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);

Possible resize constrains:

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

Using flip with flipping directions

// Flipping directions ($direction)
$image->flip(Yii\image\drivers\Image::HORIZONTAL);

Possible flipping directions:

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