PHPackages                             dkhru/yii2-image-store - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. dkhru/yii2-image-store

ActiveYii2-extension[File &amp; Storage](/categories/file-storage)

dkhru/yii2-image-store
======================

Component for store all images in project as simple capacity save way.

125PHP

Since Dec 26Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dkhru/yii2-image-store)[ Packagist](https://packagist.org/packages/dkhru/yii2-image-store)[ RSS](/packages/dkhru-yii2-image-store/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Yii2 Image Store
================

[](#yii2-image-store)

Component for store all images in project as simple capacity save way

Features
--------

[](#features)

- Save unique images by file hash and share them with all models
- Automatic check image dependants on all models fields on delete if no dependants delete files
- Automatic create custom or predefined size variants of images
- Implement public and restricted access to image files. use symlink for public images and web controller for restricted
- Automatic attach behaviors
- Automatic crete controller map and url rules

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist dkhru/yii2-image-store "*"

```

or add

```
"dkhru/yii2-image-store": "*"

```

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

For create tables run migration:

```
  ./yii console migrate --migrationPath=@dkhru/imageStore/migrations

```

Configuration
-------------

[](#configuration)

Add fields to your DB and model that need to store images

`Schema::TYPE_BIGINT . ' UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY'`

Once the extension is installed, add component in common/config/main after db component:

```
         'iStore'=>[
            'class'=>'dkhru\imageStore\components\ImageStore',
            'storePath'=>Yii::getAlias('@common/image-store'), // Path where files generated
            'publicPath'=>Yii::getAlias('@storage'),           // Path where link generated
            'publicUrl'=>Yii::getAlias('@storageUrl'),         // Url to nginx location for Public Path
            'defaultVariants'=>[                               // Default image size for resizing
               [ 'width'=>800, 'height'=>600 ],
               [ 'width'=>180, 'height'=>135 ],
            ],
            'models'=>[                                        // array of models for attach behavior to
               [
                  'class'=>\common\models\Image::className(),  // model class
                  'fields'=>[                                  // array of fields in model for store images
                     'image_id'=>[],
                  ],
               ],
               [
                  'class'=>\common\models\User::className(),
                  'fields'=>[
                     'avatar_id'=>[
                        'variants'=>[                          // image sizes for field if not set using defaultVariants
                           [ 'width'=>128, 'height'=>128 ],
                        ],
                     ],
                  ],
               ],
            ]
         ]

```

### For initialize component run:

[](#for-initialize-component-run)

```

    ./yii istore/init

    Create FK
    Add stores

    PHP Doc for add to common\models\Image class:
     * @mixin \dkhru\imageStore\components\ImageBehavior
     * @property \dkhru\imageStore\components\ImageStore $iStore
     * @property \dkhru\imageStore\models\Image $image

    PHP Doc for add to common\models\User class:
     * @mixin \dkhru\imageStore\components\ImageBehavior
     * @property \dkhru\imageStore\components\ImageStore $iStore
     * @property \dkhru\imageStore\models\Image $image

```

This console command create foreign keys, initialize data in DB and return Class PHP Doc's for configured models

Ussage
------

[](#ussage)

Component attach behaviors for configured models on initialisation and map console and web controllers over bootstrap interface

In target models after behavior attached you can use relation to images as property named `_image`If you have only one field named image\_id you must simple use `image` without `_image`

For saving images simle use method of YourModel-&gt;`setImage(,, )`. Then saving image this method generate hash for file and look at the store if some image are stored generate don't store it Generate not stored variants, link to YourModel(set YourModel-&gt;image\_id) and return image

###  Health Score

21

—

LowBetter than 17% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/60dc5b9b13398fc2e5b645b6ff3af04c3242c4b81393718efecb9d858f56641a?d=identicon)[dkhru](/maintainers/dkhru)

---

Top Contributors

[![dkhru](https://avatars.githubusercontent.com/u/6189646?v=4)](https://github.com/dkhru "dkhru (8 commits)")

### Embed Badge

![Health badge](/badges/dkhru-yii2-image-store/health.svg)

```
[![Health](https://phpackages.com/badges/dkhru-yii2-image-store/health.svg)](https://phpackages.com/packages/dkhru-yii2-image-store)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
