PHPackages                             svsoft/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. [Image &amp; Media](/categories/media)
4. /
5. svsoft/thumbnails

ActivePhp-lib[Image &amp; Media](/categories/media)

svsoft/thumbnails
=================

php component for resizing image and creating thumbnails

044PHP

Since May 16Pushed 7y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

thumbnails
==========

[](#thumbnails)

Component for resize images on 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

For those who are developing on YII2 there is an adapter of this library [svsoft/yii2-thumbnails](https://github.com/svsoft/yii2-thumbnails)

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

[](#installation)

### Composer

[](#composer)

add to composer.json

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

and run `php composer.phar update`

Or

run `php composer.phar require svsoft/thumbnails `

Configuring and initializing the component
------------------------------------------

[](#configuring-and-initializing-the-component)

Create component with local source image storage and local thumbnail storage

```
// Creating local image storage
$imageStorage = new ImageLocalStorage();

// Create local thumbnail storage
// $dirPath - path to direcrory where storage thambnail files
// $webDirPath - public url the same folder
$thumbStorage = new ThumbLocalStorage($dirPath, $webDirPath);

// Based on these storages we create an object that creates thumbnails.
$creator = new ThumbCreator($imageStorage, $thumbStorage);

// Create thumbnail manager, where description thumbnails
$thumbManager = new ThumbManager();
$thumbManager->setThumbs([
    'content' => new Thumb([
        // simple resize 1140x1140
        new Resize(1140, 1140),
    ]),

    'favicon' => new Thumb([
        // Resize fixed size filled with transparent fields
        new ResizeFillingHandler(40, 40),
    ]),

    'productDetail' => new Thumb([
        // image handler fixed size with crop centered
        new ResizeCropHandler(600, 600),
        // watermark handler with transparent 30%
        new WatermarkHandler('/var/www/site.ru/....', 30)
    ]),

    // ...
]);

// Create component that create thumbnails.
$thumbnails = new Thumbnails($thumbManager, $creator);
```

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

```
