Yii2 helper for creating and caching webp thumbnails on real time.
The preferred way to install this extension is through composer.
- Either run
php composer.phar require "tonchik-tm/yii2-modern-thumbnailer" "*"
or add
"tonchik-tm/yii2-modern-thumbnailer": "*"
to the require section of your application's composer.json
file.
For example:
use TonchikTm\Yii2Thumb\ImageThumb;
$mode = ImageThumb::THUMBNAIL_INSET;
$options = [
'source' => [
'format' => 'webp',
'mode' => $mode
],
'img' => [
'mode' => $mode
]
];
echo ImageThumb::thumbPicture(
Yii::getAlias('@webroot/assets/example.png'),
300,
300,
$options
);
In the output we will get something like this code:
<picture data-cache="hit">
<source srcset="/assets/thumbnails/example.png.webp" type="image/webp" />
<img src="/assets/thumbnails/example.png" />
</picture>
If you use Jcrop, you can use mode ImageThumb::THUMBNAIL_CROP
:
<?php
use TonchikTm\Yii2Thumb\ImageThumb;
$crop = [
'source' => [450, 450], // Size source image where create crop coordinates
'coord' => ['x'=>100,'y'=>50,'x2'=>350,'y2'=>200,'w'=>250,'h'=>150,], // data from jCrop
];
$options = [
'mode' => ImageThumb::THUMBNAIL_CROP,
'crop' => $crop,
];
?>
<hr>
<?= ImageThumb::thumbImg(Yii::getAlias('@webroot/assets/example.png'), 250, 150, $options) . "\n"; ?>
For other functions please see the source code.
The package is in the process of developing