PHP code example of open20 / yii2-image

1. Go to this page and download the library: Download open20/yii2-image 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/ */

    

open20 / yii2-image example snippets


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

$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);

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

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

// 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;

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

     const HORIZONTAL = 0x11;
     const VERTICAL   = 0x12;
code
/config/web.php
code
'components' => array(
        ...
        'image' => array(
        	 	'class' => 'yii\image\ImageDriver',
        		'driver' => 'GD',  //GD or Imagick
        		),
		    )