PHPackages                             coolanole/yii2-gallery-manager - 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. coolanole/yii2-gallery-manager

ActiveYii2-extension[Image &amp; Media](/categories/media)

coolanole/yii2-gallery-manager
==============================

Extension for yii, that allows to manage image galleries

1.3.0(6y ago)01.9kMITPHP

Since Jun 6Pushed 6y agoCompare

[ Source](https://github.com/coolanole/yii2-gallery-manager)[ Packagist](https://packagist.org/packages/coolanole/yii2-gallery-manager)[ RSS](/packages/coolanole-yii2-gallery-manager/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

Gallery Manager usage instructions
==================================

[](#gallery-manager-usage-instructions)

Yii2 port of

(frontend part mostly without changes, but backend was rewritten almost completely)

Gallery manager screenshots (yii 1.x version, new one has bootstrap 3 styles):

[![GalleryManager images list](https://camo.githubusercontent.com/0ac467c977458a29b9c5f0d23eae526e587d800ca0fa146d6d56ccd662310b51/687474703a2f2f636f6f6c616e6f6c652e63632e75612f73637275702f63692f6568316e317468366f306338302e706e67 "Gallery Manager Screenshot")](https://camo.githubusercontent.com/0ac467c977458a29b9c5f0d23eae526e587d800ca0fa146d6d56ccd662310b51/687474703a2f2f636f6f6c616e6f6c652e63632e75612f73637275702f63692f6568316e317468366f306338302e706e67)

Few more screenshots: [drag &amp; drop upload](http://coolanole.cc.ua/scrup/6w/64q4icig84oo0.png "Drag & Drop image upload"), [editing image information](http://coolanole.cc.ua/scrup/za/gfc68h5b4gksg.png "Edit image information"), [upload progress](http://coolanole.cc.ua/scrup/8v/tijrezh7oksk8.png "upload progress"),

Features
--------

[](#features)

1. AJAX image upload
2. Optional name and description for each image
3. Possibility to arrange images in gallery
4. Ability to generate few versions for each image with different configurations
5. Drag &amp; Drop

Decencies
---------

[](#decencies)

1. Yii2
2. Twitter bootstrap assets (version 3)
3. Imagine library
4. JQuery UI (included with Yii)

Installation:
-------------

[](#installation)

The preferred way to install this extension is through [composer](https://getcomposer.org/).

Either run

`php composer.phar require --prefer-dist coolanole/yii2-gallery-manager "*@dev"`

or add

`"coolanole/yii2-gallery-manager": "*@dev"`

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

### Prepare

[](#prepare)

Add migration to create table for images:

```
class m150318_154933_gallery_ext
    extends coolanole\yii2\galleryManager\migrations\m140930_003227_gallery_manager
{

}
```

Or better - copy migration to you application(but be sure to **remove namespace from it** - it should be in global namespace)

### Add configurations for upload and store images

[](#add-configurations-for-upload-and-store-images)

Add GalleryBehavior to your model, and configure it, create folder for uploaded files.

```
use coolanole\yii2\galleryManager\GalleryBehavior;

class Product extends \yii\db\ActiveRecord
{
...
public function behaviors()
{
    return [
         'galleryBehavior' => [
             'class' => GalleryBehavior::className(),
             'type' => 'product',
             'extension' => 'jpg',
             'directory' => Yii::getAlias('@webroot') . '/images/product/gallery',
             'url' => Yii::getAlias('@web') . '/images/product/gallery',
             'versions' => [
                 'small' => function ($img) {
                     /** @var \Imagine\Image\ImageInterface $img */
                     return $img
                         ->copy()
                         ->thumbnail(new \Imagine\Image\Box(200, 200));
                 },
                 'medium' => function ($img) {
                     /** @var \Imagine\Image\ImageInterface $img */
                     $dstSize = $img->getSize();
                     $maxWidth = 800;
                     if ($dstSize->getWidth() > $maxWidth) {
                         $dstSize = $dstSize->widen($maxWidth);
                     }
                     return $img
                         ->copy()
                         ->resize($dstSize);
                 },
             ]
         ]
    ];
}
```

See also [documentations of imagine](https://imagine.readthedocs.io/en/master/usage/introduction.html) for image transformations.

Add GalleryManagerAction in controller somewhere in your application. Also on this step you can add some security checks for this action.

```
use coolanole\yii2\galleryManager\GalleryManagerAction;

class ProductController extends Controller
{
...
public function actions()
{
    return [
       'galleryApi' => [
           'class' => GalleryManagerAction::className(),
           // mappings between type names and model classes (should be the same as in behaviour)
           'types' => [
               'product' => Product::className()
           ]
       ],
    ];
}
```

Add ImageAttachmentWidget somewhere in you application, for example in editing from.

```
use coolanole\yii2\galleryManager\GalleryManager;

/* @var $this yii\web\View */
/* @var $model Product */
?>
...
