PHPackages                             zxbodya/yii2-image-attachment - 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. zxbodya/yii2-image-attachment

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

zxbodya/yii2-image-attachment
=============================

Extension for yii, to handle images attached to ActiveRecord

3418.0k13[3 issues](https://github.com/zxbodya/yii2-image-attachment/issues)PHP

Since Jan 6Pushed 4y ago5 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

ImageAttachment
===============

[](#imageattachment)

This extension intended to handle images associated with model.

Extensions provides user friendly widget, for image upload and removal.

[![Yii2 image attachement screenshot](https://camo.githubusercontent.com/c2abf09f4ce0814091826ff0de36740817bf5f11c87fc66b7406076bcf078a15/687474703a2f2f7a78626f6479612e63632e75612f73637275702f39302f6f7963616235626377306777632e706e67)](https://camo.githubusercontent.com/c2abf09f4ce0814091826ff0de36740817bf5f11c87fc66b7406076bcf078a15/687474703a2f2f7a78626f6479612e63632e75612f73637275702f39302f6f7963616235626377306777632e706e67)

Features
--------

[](#features)

1. Asynchronous image upload
2. Ability to generate few image versions with different configurations
3. Drag &amp; Drop

Decencies
---------

[](#decencies)

1. Yii2
2. Twitter bootstrap assets
3. Imagine library

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

[](#installation)

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

Either run

`php composer.phar require --prefer-dist zxbodya/yii2-image-attachment "*@dev"`

or add

`"zxbodya/yii2-image-attachment": "*@dev"`

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

Usage
-----

[](#usage)

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

```
public function behaviors()
{
    return [
        'coverBehavior' => [
            'class' => ImageAttachmentBehavior::className(),
            // type name for model
            'type' => 'post',
            // image dimmentions for preview in widget
            'previewHeight' => 200,
            'previewWidth' => 300,
            // extension for images saving
            'extension' => 'jpg',
            // path to location where to save images
            'directory' => Yii::getAlias('@webroot') . '/images/post/cover',
            'url' => Yii::getAlias('@web') . '/images/post/cover',
            // additional image versions
            'versions' => [
                'small' => function ($img) {
                    /** @var ImageInterface $img */
                    return $img
                        ->copy()
                        ->resize($img->getSize()->widen(200));
                },
                'medium' => function ($img) {
                    /** @var ImageInterface $img */
                    $dstSize = $img->getSize();
                    $maxWidth = 800;
                    if ($dstSize->getWidth() > $maxWidth) {
                        $dstSize = $dstSize->widen($maxWidth);
                    }
                    return [
                        $img->copy()->resize($dstSize),
                        ['jpeg_quality' => 80], // options used when saving image (Imagine::save)
                    ];
                },
            ]
        ]
    ];
}
```

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

```
public function actions()
{
    return [
        'imgAttachApi' => [
            'class' => ImageAttachmentAction::className(),
            // mappings between type names and model classes (should be the same as in behaviour)
            'types' => [
                'post' => Post::className()
            ]
        ],
    ];
}
```

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

```
echo ImageAttachmentWidget::widget(
    [
        'model' => $model,
        'behaviorName' => 'coverBehavior',
        'apiRoute' => 'test/imgAttachApi',
    ]
)
```

Done! Now, you can use it in other places in app too:

```
if ($model->getBehavior('coverBehavior')->hasImage()) {
    echo Html::img($model->getBehavior('coverBehavior')->getUrl('medium'));
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 86.1% 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/3f47929617cbb1dee5a095baccb865ab5e30ad7155f5b30b081b50249806593d?d=identicon)[zxbodya](/maintainers/zxbodya)

---

Top Contributors

[![zxbodya](https://avatars.githubusercontent.com/u/446117?v=4)](https://github.com/zxbodya "zxbodya (31 commits)")[![muhammadcahya](https://avatars.githubusercontent.com/u/4241620?v=4)](https://github.com/muhammadcahya "muhammadcahya (2 commits)")[![Faryshta](https://avatars.githubusercontent.com/u/2029247?v=4)](https://github.com/Faryshta "Faryshta (1 commits)")[![garando](https://avatars.githubusercontent.com/u/7852028?v=4)](https://github.com/garando "garando (1 commits)")[![paskuale75](https://avatars.githubusercontent.com/u/9800?v=4)](https://github.com/paskuale75 "paskuale75 (1 commits)")

---

Tags

yii2yii2-extension

### Embed Badge

![Health badge](/badges/zxbodya-yii2-image-attachment/health.svg)

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

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

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

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15161.6M2.6k](/packages/illuminate-filesystem)[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)[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)

PHPackages © 2026

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