PHP code example of flaviovs / yii2-imagefilter

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

    

flaviovs / yii2-imagefilter example snippets


   'components' => [
       // (...)
       'imagefilter' => [
           'class' => \fv\yii\imagefilter\Component::class,
           'pipelines' => [
               'thumbnail-100' => [
                   'filters' => [
                       [
                           'class' => 'app\filters\Scale',
                           'width' => 100,
                           'height' => 100,
                       ],
                   ],
               ],
           ],
       ],
       // (...)
   ]
   

   namespace app\controllers;
   
   class ImageController extends \yii\web\Controller
   {
	   public function actions()
	   {
		   return [
			   'filter' => \fv\yii\imagefilter\Action::class,
		   ];
	   }
   }
   

   'urlManager' => [
       // (...)
       'rules' => [
           // (...)
           'assets/img/<pipeline>/<version>/<src:.+>' => 'image/filter',
           // (...)
        ],
   ],
   

   $app->imagefilter->url('thumbnail-100', '/img/foobar.png')
   

   $app->imagefilter->img('thunbnail-100', '/img/foobar.png', ['alt' => 'Foo bar']);
   

class MyFilter extends \yii\base\BaseObject implements \fv\yii\imagefilter\Filter
{
    public $width;
    public $height;

    public function filterImage($src, $dest)
	{
         \yii\imagine\Image::thumbnail($src, $this->width, $this->height)
            ->save($dest);
    }
}

'standard-watermark' => [
    'filters' => [
        [
            'class' => 'app\filters\Scale',
            'width' => 400,
            'height' => 400,
        ],
        [
            'class' => 'app\filters\AddWatermark',
            'text' => 'My Image',
            'fontSize' => 10,
            'x' => -1,
            'y' => -1,
        ],
    ],
]

'standard-watermark' => [
    'version' => '1', // Force a new version
    'filters' => [
        // (...)
        [
            // (...)
            'fontSize' => 12,
            // (...)
        ],
    ],
]