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

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

bscheshirwork/yii2-gallery-manager-imaginary
============================================

Extension for yii, that allows to manage image galleries use imaginary

074PHP

Since Nov 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/bscheshirwork/yii2-gallery-manager-imaginary)[ Packagist](https://packagist.org/packages/bscheshirwork/yii2-gallery-manager-imaginary)[ RSS](/packages/bscheshirwork-yii2-gallery-manager-imaginary/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (4)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/85a947217ba6d34b3f62248f0c77fbc45263e4abac414f251ef534a640ed5891/687474703a2f2f7a78626f6479612e63632e75612f73637275702f63692f6568316e317468366f306338302e706e67 "Gallery Manager Screenshot")](https://camo.githubusercontent.com/85a947217ba6d34b3f62248f0c77fbc45263e4abac414f251ef534a640ed5891/687474703a2f2f7a78626f6479612e63632e75612f73637275702f63692f6568316e317468366f306338302e706e67)

Few more screenshots: [drag &amp; drop upload](http://zxbodya.cc.ua/scrup/6w/64q4icig84oo0.png "Drag & Drop image upload"), [editing image information](http://zxbodya.cc.ua/scrup/za/gfc68h5b4gksg.png "Edit image information"), [upload progress](http://zxbodya.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. Imaginary docker image
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 bscheshirwork/yii2-gallery-manager-imaginary "*@dev"`

or add

`"bscheshirwork/yii2-gallery-manager-imaginary": "*@dev"`

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

Usage
-----

[](#usage)

### docker-compose

[](#docker-compose)

```
  imaginary:
    image: h2non/imaginary:latest
    # optionally mount a volume as local image source
    volumes:
      - ./storage/web:/mnt/data
    environment:
      PORT: 9000
    command: -enable-url-source -mount /mnt/data
    expose:
      - "9000" #for service php
    ports:
      - "9000:9000"

```

### Prepare

[](#prepare)

Add migration namespace to console config:

```
return [
    'id' => 'app-console',
...
    'controllerMap' => [
        'migrate' => [
            'class' => yii\console\controllers\MigrateController::class,
            // Since version 2.0.12 an array can be specified for loading migrations from multiple sources.
            'migrationPath' => [
                '@app/migrations',
                '@yii/rbac/migrations/',
            ],
            'migrationNamespaces' => [
                'bscheshirwork\yii2\galleryManager\migrations',
                ...
            ],
        ],
...
```

### 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 bscheshirwork\yii2\galleryManager\GalleryBehavior;

class Product extends \yii\db\ActiveRecord
{
...
public function behaviors()
{
        $model = $this;

        return [
            'galleryBehavior' => [
                'class' => GalleryBehavior::class,
                'type' => 'nestedObject', // @see CrudController::actions()
                'extension' => 'jpg',
                'directory' => Yii::getAlias('@storageWeb') . ($galleryPath = '/images/gallery/product'),
                'url' => Yii::getAlias('@storageUrl') . $galleryPath,
                'imaginaryDirectory' => $galleryPath,
                'versions' => [
                    'small' => function ($originalImagePath, $originalImagePathForImagine) use ($model) {
                        $width = 400;
                        $height = 274;
                        /** @var GalleryBehavior $behavior */
                        $behavior = $model->getBehavior('galleryBehavior');
                        $httpQuery = http_build_query([
                            'file' => $originalImagePathForImagine,
                            'width' => $width,
                            'height' => $height,
                        ]);

                        $url = $behavior->imaginary . '/crop?' . $httpQuery;

                        return file_get_contents($url);
                    },
                ],
            ],
        ];
}
```

See also [documentations of imaginary http API](https://github.com/h2non/imaginary#http-api) 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 bscheshirwork\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 bscheshirwork\yii2\galleryManager\GalleryManager;

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