PHP code example of mauglee / yii2-easyimage

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

    

mauglee / yii2-easyimage example snippets


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',
        ]
    ],
];

Yii::$app->easyImage->thumbOf('/path/to/image.jpg', ['rotate' => 90]);

Yii::$app->easyImage->thumbOf('image.jpg', ['rotate' => 90],  ['class' => 'image']);

Yii::$app->easyImage->thumbOf('image.png', [
    'resize' => ['width' => 100, 'height' => 100],
    'rotate' => ['degrees' => 90],
    'sharpen' => 50,
    'background' => '#ffffff',
    'type' => 'jpg',
    'quality' => 60,
  ]);

// 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',
        ] );
    }
}

php composer.phar