PHP code example of sadovojav / yii2-image-thumbnail

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

    

sadovojav / yii2-image-thumbnail example snippets

 composer.phar 

'components' => [
    'thumbnail' => [
        'class' => 'sadovojav\image\Thumbnail',
    ],
],

'options' => [
    'placeholder' => [
        'type' => sadovojav\image\Thumbnail::PLACEHOLDER_TYPE_URL,
        'backgroundColor' => '#f5f5f5',
        'textColor' => '#cdcdcd',
        'textSize' => 30,
        'text' => 'No image'
    ],
    'quality' => 92,
    'format' => null, //webp, jpg, png
    'tinyPng' => [
        'apiKey' => null
    ]
]

echo Yii::$app->thumbnail->img($file, $params, $options);

<?= Yii::$app->thumbnail->img(IMAGE_SRC, [
    'thumbnail' => [
        'width' => 320,
        'height' => 230,
    ],
    'placeholder' => [
        'width' => 320,
        'height' => 230
    ]
]); 

echo Yii::$app->thumbnail->url($file, $params);

<?= Yii::$app->thumbnail->url(IMAGE_SRC, [
    'thumbnail' => [
        'width' => 320,
        'height' => 230,
    ],
    'placeholder' => [
        'width' => 320,
        'height' => 230
    ]
]); 

echo Yii::$app->thumbnail->img($file, $params, $options);

<?= Yii::$app->thumbnail->img(null, [
    'placeholder' => [
        'width' => 320,
        'height' => 230
    ]
]); 

echo Yii::$app->thumbnail->url($file, $params, $options);

<?= Yii::$app->thumbnail->url(null, [
    'placeholder' => [
        'width' => 320,
        'height' => 230
    ]
]); 

'resize' => [
    'width' => 320,
    'height' => 200
]

'crop' => [
    'width' => 250,
    'height' => 200,
]

'thumbnail' => [
    'width' => 450,
    'height' => 250,
]

'placeholder' => [
    'width' => 450,
    'height' => 250,
]

'watermark' => [
    'image' => IMAGE_SRC
    'posX' => 0,
    'posY' => 0,
    'width' => 50,
    'height' => 50
]

'compress' => true