yii2-easy-thumbnail-image-helper

  • Owner: himiklab/yii2-easy-thumbnail-image-helper
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Easy Thumbnail Image Helper for Yii2

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");
        }
    }
} 

Main metrics

Overview
Name With Ownerhimiklab/yii2-easy-thumbnail-image-helper
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2014-07-19 12:54:04
Pushed At2018-11-14 08:41:05
Last Commit At2018-11-12 14:51:07
Release Count8
Last Release Name1.1.5 (Posted on )
First Release Name1.0.2 (Posted on )
用户参与
Stargazers Count46
Watchers Count5
Fork Count16
Commits Count29
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count2
Pull Requests Open Count0
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private