PHPackages                             svsoft/yii2-thumbnails - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. svsoft/yii2-thumbnails

ActiveYii2-extension

svsoft/yii2-thumbnails
======================

Yii2 component for resizing image and creating thumbnails based on svsoft/thumbnails

038PHP

Since May 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/svsoft/yii2-thumbnails)[ Packagist](https://packagist.org/packages/svsoft/yii2-thumbnails)[ RSS](/packages/svsoft-yii2-thumbnails/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-thumbnails
===============

[](#yii2-thumbnails)

It is adapter for Yii2 based on [svsoft/thumbnails](https://github.com/svsoft/thumbnails) component for resize images on native php.

Creates thumbnails of pictures with various handlers: resize, crop, fill, watermark. You can also create your handlers, and add them to the description of the thumbnail.

### Features:

[](#features)

- Supports different types of source image storage.
- Supports various types of thumbnail storage
- Ability to create your own storage types (ftp, Database, Http)
- Simple apply of new handlers In the previously described thumbnails
- Ability to create your own custom image handlers

In the library everywhere is used interfaces, you can implementation necessary logic in your classes

Installation
------------

[](#installation)

### Composer

[](#composer)

add to composer.json

```
{
	"require": {
  		"svsoft/yii2-thumbnails": "*"
	}
}
```

and run `php composer.phar update`

Or

run `php composer.phar require svsoft/yii2-thumbnails `

Config
------

[](#config)

Add to config

```
'components' => [
    // ....
    'thumbnails' => [
                'class' => \svsoft\yii\thumbnails\Thumbnails::class,
                //
                'dirPath' => '@app/web/resize',
                'webDirPath' => '@web/resize',
                'thumbs' => [
                    // Short description thumbnail
                    'logo'=> [
                        // simple resize 200x40
                        'width'  => 200,
                        'height' => 40,
                    ],
                    'favicon'=> [
                        // Resize fixed size filled with transparent fields
                        'class'=> \svsoft\yii\thumbnails\handlers\ResizeFillingHandlerFactory::class,
                        'width'  => 40,
                        'height'  => 40,
                    ],
                    // Full description of thumbnail
                    'product'=>[
                        'class' => \svsoft\yii\thumbnails\ThumbFactory::class,
                        'handlers' => [
                            [
                                'class' => \svsoft\yii\thumbnails\handlers\ResizeCropHandlerFactory::class,
                                'width'  => 600,
                                'height' => 600,
                            ],
                            [
                                'class' => \svsoft\yii\thumbnails\handlers\WatermarkHandlerFactory::class,
                                'watermarkFilePath' => '@app/web/images/watermark.jpg',
                                'opacity' => 50,
                            ],
                        ],
                    ],

                    // ...
                ]
            ],    // ....
],
```

#### Properties

[](#properties)

- dirPath - Path to thumbnail file storage directory
- webDirPath - Public web path to thumbnail file storage directory
- thumbs - List of thumbnail configuration
- $imageStorage - Not required. Description of image storage. Now implementation only local image storage which is set by default set. (FTP, HTTP, DB NOT IMPLEMENTATION!)
- $thumbStorage - Not required. Description of thumb storage. Now implementation only local thumb storage which is set by default set. (FTP, HTTP, DB NOT IMPLEMENTATION!)

#### Handler classes

[](#handler-classes)

```
\svsoft\yii\thumbnails\handlers\ResizeCropHandlerFactory - fixed resize and crop
\svsoft\yii\thumbnails\handlers\ResizeFillingHandlerFactory - fixed resize with filling fields
\svsoft\yii\thumbnails\handlers\ResizeHandlerFactory - resize to a certain size
\svsoft\yii\thumbnails\handlers\WatermarkHandlerFactory - watermark overlay

```

Each handler has its own settings, you can see them in the appropriate class/

You can add your handlers.

Using
-----

[](#using)

How to get the component where it will be used depends on the application and developer. via service locator, singleton, container, etc.

Example output favicon

```
