2017 © Pedro Peláez
 

yii2-extension yii2-easyimage

Image Component for Yii2

image

mauglee/yii2-easyimage

Image Component for Yii2

  • Tuesday, February 21, 2017
  • by mauglee
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Image Component for Yii2

Image Component for Yii2, (*1)

This extension is based on yii-easyImage, (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require mauglee/yii2-easyimage

or add, (*5)

"mauglee/yii2-easyimage": "@dev"

to the require-dev 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' => true,
            'pixel_ratio'   => [ 2, 3 ], // Device pixels per CSS pixel (retina stuff)
            '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)

Example using different filetypes, diferrent images source path:, (*13)

// in real situation those filenames are retrieved from DB 
$images = [
    '01.jpg',
    '02.jpg',
    '03.png',
];

foreach ( $images as $image ) {
    $file_path = Yii::getAlias( '@app/data/image/logo/' ) . $image;
    if ( is_file( $file_path ) ) {
        echo Yii::$app->easyImage->thumbOf( $file_path, [
            'resize'  => [ 'width' => 300, 'height' => 300 ],
            'type'    => 'jpg',
            'quality' => '86',
        ] );
    }
}

Parameters

  • string $file required - Image file path
  • array $params - Image manipulation methods
  • array $htmlOptions - options for Html::img()

For full details on usage, see the documentation on authors page. Note: Some differencies may occur, because original version is written for Yii v1, (*14)

The Versions

21/02 2017

dev-master

9999999-dev

Image Component for Yii2

  Sources   Download

MIT

The Requires

 

by Avatar cliff363825
by Maug Lee

yii2 image

13/07 2016

1.0.2

1.0.2.0

Image Component for Yii2

  Sources   Download

MIT

The Requires

 

by Avatar cliff363825

yii2 image

13/07 2016

1.0.1

1.0.1.0

Image Component for Yii2

  Sources   Download

MIT

The Requires

 

by Avatar cliff363825

yii2 image

30/11 2015

1.0.0

1.0.0.0

Image Component for Yii2

  Sources   Download

MIT

The Requires

 

by Avatar cliff363825

yii2 image