PHPackages                             unique/yii2-model-image - 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. unique/yii2-model-image

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

unique/yii2-model-image
=======================

Allows to easily attach an image to a model in Yii2 framework

026PHP

Since Apr 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/uniquexor/yii2-model-image)[ Packagist](https://packagist.org/packages/unique/yii2-model-image)[ RSS](/packages/unique-yii2-model-image/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 ModelImage
===============

[](#yii2-modelimage)

A behavior for Yii2 Framework model class, that allows to easily attach an image, when saving a model.

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

[](#installation)

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

Either run

```
composer require unique/yii2-model-image

```

or add

```
"unique/yii2-model-image": "@dev"

```

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

To create DB tables run migration file:

```
./yii migrate --migrationPath="vendor/unique/yii2-model-image/src/migrations"

```

Usage
-----

[](#usage)

In order to use the behavior, you first need to load the module. Module can only be loaded once. Add the following to your config file:

```

```

Then your model can implement a behavior like so:

```
    class Profile extends \yii\db\ActiveRecord {

        // ...
        public $profile_photo;

        public function behaviors() {

            return array_merge( parent::behaviors(), [
                'image' => [
                    'class' => ImageBehavior::class,
                    'uploaded_file_attribute' => 'profile_photo',
                    'image_attribute' => 'profile_photo_id',
                    'group' => 'user_profile_photo',
                ]
            ] );
        }

        public function rules() {

            return [
                // ...
                [ [ 'profile_photo' ], 'file', 'extensions' => 'jpg' ],
            ];
        }
    }
```

Now, when saving Profile model, an uploaded image will be saved automatically, also generating the two associated versions of the image called `thumb_small` and `thumb_large`. If an error occurs, while saving the image, `Profile::save()` will return false and an error will be set on the `Profile::$profile_photo` attribute.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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/2a798acb845b9c8ab35c7853f5a6bfd5e3b2b0578faea86e873fa269ea997371?d=identicon)[unique](/maintainers/unique)

---

Top Contributors

[![uniquexor](https://avatars.githubusercontent.com/u/6176836?v=4)](https://github.com/uniquexor "uniquexor (10 commits)")

### Embed Badge

![Health badge](/badges/unique-yii2-model-image/health.svg)

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

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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