alkurn/yii2-thumbnail

Yii2 helper for creating and caching thumbnails on real time

Installs: 601

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Type:yii2-extension

dev-master 2022-05-05 04:14 UTC

This package is not auto-updated.

Last update: 2022-06-16 04:46:30 UTC


README

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 --prefer-dist "alkurn/yii2-thumbnail" "dev-master"

or add

"alkurn/yii2-thumbnail" : "*"

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

  • Add a new lines in bootstrap file of your application, for example:
Yii::setAlias('@uploads', dirname(dirname(__DIR__)) . '/uploads');
Yii::setAlias('@cache', dirname(dirname(__DIR__)) . '/uploads/cache');
Yii::setAlias('@image',   '/uploads/cache');
  • Add a new component in components section of your application's configuration file (optional), for example:
'components' => [
    'thumbnail' => [
                'class' => 'alkurn\thumbnail\Thumbnail',
                'cacheAlias'    => Yii::getAlias('@cache/'),
                'uploadsAlias'  => Yii::getAlias('@uploads/'),
                'imageAlias'    => Yii::getAlias('@image/'),
                'defaultImage'  => 'default.png',
            ],
],

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 alkurn\thumbnail\ThumbnailImage;

echo ThumbnailImage::thumbnailImg(
    $model->image,
    50,
    50,
    ThumbnailImage::THUMBNAIL_OUTBOUND,
    ['alt' => $model->image]
);