1-more-thing/yii2-easy-thumbnail-image-helper

Yii2 helper for creating and caching thumbnails on real time

Maintainers

👁 airmoi

Package info

github.com/1-more-thing/yii2-easy-thumbnail-image-helper

Type:yii2-extension

pkg:composer/1-more-thing/yii2-easy-thumbnail-image-helper

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1 2023-03-31 22:15 UTC

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 63805a9896b1767eeec9eadb3c850f8bce5f6f5e

imagethumbnailhelperyii2

This package is auto-updated.

Last update: 2026-06-29 02:03:26 UTC


README

👁 Packagist
👁 Packagist
👁 license

Yii2 helper for creating and caching thumbnails on real time.

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require "himiklab/yii2-easy-thumbnail-image-helper" "*"

or add

"himiklab/yii2-easy-thumbnail-image-helper" : "*"

to the require section of your application's composer.json file.

  • Add a new component in components section of your application's configuration file, for example:
'components' => [
 'thumbnail' => [
 'class' => 'himiklab\thumbnail\EasyThumbnail',
 'cacheAlias' => 'assets/gallery_thumbnails',
 ],
],

and in bootstrap section, for example:

'bootstrap' => ['log', 'thumbnail'],

It is necessary if you want to set global helper's settings for the application.

Usage

For example:

use himiklab\thumbnail\EasyThumbnailImage;

echo EasyThumbnailImage::thumbnailImg(
 $model->pictureFile,
 50,
 50,
 EasyThumbnailImage::THUMBNAIL_OUTBOUND,
 ['alt' => $model->pictureName]
);

or

use himiklab\thumbnail\EasyThumbnailImage;

echo EasyThumbnailImage::thumbnailImg(
 'http://...',
 50,
 50,
 EasyThumbnailImage::THUMBNAIL_OUTBOUND,
);

For other functions please see the source code.

If you want to handle errors that appear while converting to thumbnail by yourself, please make your own class and inherit it from EasyThumbnailImage. In your class replace only protected method errorHandler. For example

class ThumbHelper extends \himiklab\thumbnail\EasyThumbnailImage
{

 protected static function errorHandler($error, $filename)
 {
 if ($error instanceof \himiklab\thumbnail\FileNotFoundException) {
 return \yii\helpers\Html::img('@web/images/notfound.png');
 } else {
 $filename = basename($filename);
 return \yii\helpers\Html::a($filename,"@web/files/$filename");
 }
 }
}