PHP code example of yii-ext / yii-easyimage
1. Go to this page and download the library: Download yii-ext/yii-easyimage library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yii-ext / yii-easyimage example snippets
'components'=>array(
//...
'easyImage' => array(
'class' => 'application.extensions.easyimage.EasyImage',
'password' => 'password' // used for image action
//'driver' => 'GD',
//'quality' => 100,
//'cachePath' => '/assets/easyimage/',
//'cacheTime' => 2592000,
//'retinaSupport' => false,
),
'import' => array(
//...
'ext.easyimage.EasyImage'
),
$image = new EasyImage('/path/to/image.jpg');
$image->resize(100, 100);
$image->save('/full/path/to/thumb.jpg');
// Create and autocache
Yii::app()->easyImage->thumbOf('/path/to/image.jpg', array('rotate' => 90));
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('rotate' => 90), array('class' => 'image'));
// or
Yii::app()->easyImage->thumbOf('image.png',
array(
'resize' => array('width' => 100, 'height' => 100),
'rotate' => array('degrees' => 90),
'sharpen' => 50,
'background' => '#ffffff',
'type' => 'jpg',
'quality' => 60,
));
Yii::app()->easyImage->thumbSrcOf('image.jpg', array('crop' => array('width' => 100, 'height' => 100)));
$image->resize(100, 100, EasyImage::RESIZE_AUTO);
Yii::app()->easyImage->thumbOf('image.jpg', array('resize' => array('width' => 100, 'height' => 100)));
$image->crop(100, 100);
Yii::app()->easyImage->thumbOf('image.jpg', array('crop' => array('width' => 100, 'height' => 100)));
$image->rotate(45);
Yii::app()->easyImage->thumbOf('image.jpg', array('rotate' => array('degrees' => 45)));
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('rotate' => 45));
$image->flip(EasyImage::FLIP_HORIZONTAL);
Yii::app()->easyImage->thumbOf('image.jpg', array('flip' => array('direction' => EasyImage::FLIP_HORIZONTAL)));
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('flip' => EasyImage::FLIP_VERTICAL));
$image->sharpen(20);
Yii::app()->easyImage->thumbOf('image.jpg', array('sharpen' => array('amount' => 20)));
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('sharpen' => 20));
// Create a 50 pixel reflection that fades from 0-100% opacity
$image->reflection(50);
// Create a 50 pixel reflection that fades from 100-0% opacity
$image->reflection(50, 100, TRUE);
// Create a 50 pixel reflection that fades from 0-60% opacity
$image->reflection(50, 60, TRUE);
Yii::app()->easyImage->thumbOf('image.jpg', array('reflection' => array('height' => 50)));
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('reflection'));
$mark = new EasyImage('watermark.png');
$image->watermark($mark, TRUE, TRUE);
// or
$image->watermark('watermark.png', 20, 20);
Yii::app()->easyImage->thumbOf('image.jpg', array('watermark' => array('watermark' => 'mark.png', 'opacity' => 50)));
$image->background('#000', 50);
Yii::app()->easyImage->thumbOf('image.jpg', array('background' => array('color' => '#ffffff', 'opacity' => 50)));
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('background' => '#ffffff'));
Yii::app()->easyImage->thumbOf('image.jpg', array('quality' => 60)));
//not support: $image->quality(60);
// see $image->render(NULL, 60);
Yii::app()->easyImage->thumbOf('image.png', array('type' => 'jpg')));
//not support: $image->type('jpg');
// see $image->render('jpg');
// Save the image as a PNG
$image->save('image.png');
// Overwrite the original image
$image->save();
// Render the image at 50% quality
$data = $image->render(NULL, 50);
// Render the image as a PNG
$data = $image->render('png');