2017 © Pedro Peláez
 

yii2-extension yii2-easy-thumbnail-image-helper

Yii2 helper for creating and caching thumbnails on real time

image

assayer-pro/yii2-easy-thumbnail-image-helper

Yii2 helper for creating and caching thumbnails on real time

  • Thursday, March 8, 2018
  • by assayer-pro
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 13 Forks
  • 0 Open issues
  • 7 Versions
  • 200 % Grown

The README.md

Easy Thumbnail Image Helper for Yii2

Yii2 helper for creating and caching thumbnails on real time., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

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

or add, (*3)

"assayer-pro/yii2-easy-thumbnail-image-helper" : "*"

to the require section of your application's composer.json file., (*4)

  • Add a new component in components section of your application's configuration file (optional), for example:
'components' => [
    'thumbnail' => [
        'class' => 'assayerpro\thumbnail\EasyThumbnailImage',
        'cacheAlias' => 'assets/gallery_thumbnails',
        'quality' => 90,
    ],
],

It is necessary if you want to set global helper's settings for the application., (*5)

Usage

For example:, (*6)

use assayerpro\thumbnail\EasyThumbnailImage;

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

or, (*7)

use assayerpro\thumbnail\EasyThumbnailImage;

echo Yii::$app->thumbnail->thumbnailImg(
    'http://...',
    50,
    50,
    EasyThumbnailImage::THUMBNAIL_OUTBOUND,
);

If one of thumbnail dimensions is set to null, another one is calculated automatically based on aspect ratio of original image. Note that calculated thumbnail dimension may vary depending on the source image in this case., (*8)

use assayerpro\thumbnail\EasyThumbnailImage;

echo Yii::$app->thumbnail->thumbnailImg(
    $model->pictureFile,
    50,
    null
);

If both dimensions are specified, resulting thumbnail would be exactly the width and height specified. How it's achieved depends on the mode., (*9)

For other functions please see the source code., (*10)

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, (*11)

class ThumbHelper extends \assayerpro\thumbnail\EasyThumbnailImage
{

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

The Versions

08/03 2018

dev-master

9999999-dev

Yii2 helper for creating and caching thumbnails on real time

  Sources   Download

MIT

The Requires

 

yii2 helper image thumbnail

08/03 2018

dev-develop

dev-develop

Yii2 helper for creating and caching thumbnails on real time

  Sources   Download

MIT

The Requires

 

yii2 helper image thumbnail

08/03 2018

1.2.0

1.2.0.0

Yii2 helper for creating and caching thumbnails on real time

  Sources   Download

MIT

The Requires

 

yii2 helper image thumbnail

03/11 2017

1.1.1

1.1.1.0

Yii2 helper for creating and caching thumbnails on real time

  Sources   Download

MIT

The Requires

 

yii2 helper image thumbnail

02/11 2017

1.1.0

1.1.0.0

Yii2 helper for creating and caching thumbnails on real time

  Sources   Download

MIT

The Requires

 

yii2 helper image thumbnail

10/01 2017

1.0.3

1.0.3.0

Yii2 helper for creating and caching thumbnails on real time

  Sources   Download

MIT

The Requires

 

yii2 helper image thumbnail

12/11 2015

1.0.2

1.0.2.0

Yii2 helper for creating and caching thumbnails on real time

  Sources   Download

MIT

The Requires

 

yii2 helper image thumbnail