Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Yii2 helper for creating and caching webp thumbnails on real time.

License

Notifications You must be signed in to change notification settings

tonchik-tm/yii2-modern-thumbnailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modern Thumbnail Image Helper for Yii2

Latest Stable Version Total Downloads Latest Unstable Version License

Yii2 helper for creating and caching webp thumbnails on real time.

Installation

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.

Usage

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

About

Yii2 helper for creating and caching webp thumbnails on real time.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages