PHPackages                             numkms/yii2-images - 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. numkms/yii2-images

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

numkms/yii2-images
==================

yii2 images module for storing images

2.0.0.4(4y ago)256BSD-3-ClausePHP

Since Jul 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/numkms/yii2-images)[ Packagist](https://packagist.org/packages/numkms/yii2-images)[ RSS](/packages/numkms-yii2-images/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (6)Versions (14)Used By (0)

yii2-images
===========

[](#yii2-images)

Yii2-images is yii2 module that allows to attach images to any of your models, next you can get images in any sizes, also you can set main image of images set.

Since 2.0 you can upload your files simply with use files attributes;

Module supports Imagick and GD libraries, you can set up it in module settings.

Usage instance:
---------------

[](#usage-instance)

```
$model = Model::findOne(12); //Model must have id

//If an image is first it will be main image for this model
$model->attachImage('../../image.png');

//But if you need set another image as main, use second arg
$model->attachImage('../../image2.png', true);

//get all images
$images = $model->getImages();
foreach($images as $img){
    //retun url to full image
    echo $img->getUrl();

    //return url to proportionally resized image by width
    echo $img->getUrl('300x');

    //return url to proportionally resized image by height
    echo $img->getUrl('x300');

    //return url to resized and cropped (center) image by width and height
    echo $img->getUrl('200x300');
}

//Returns main model image
$image = $model->getImage();

if($image){
    //get path to resized image
    echo $image->getPath('400x300');

    //path to original image
    $image->getPathToOrigin();

    //will remove this image and all cache files
    $model->removeImage($image);
}
```

Details
-------

[](#details)

1. Get images

    ```
    $model->getImage(); //returns main image for model (first added image or setted as main)

    $model->getImages(); //returns array with images

    //If there is no images for model, above methods will return PlaceHolder images or null
    //If you want placeholder set up it in module configuration (see documentation)
    ```
2. Remove image/images

    ```
    $model->removeImage($image); //you must to pass image (object)

    $model->removeImages(); //will remove all images of this model
    ```
3. Set main image

    ```
    $model->attachImage($absolutePathToImage, true); //will attach image and make it main

    foreach($model->getImages() as $img){
        if($img->id == $ourId){
            $model->setMainImage($img);//will set current image main
        }
    }
    ```
4. Get image sizes

    ```
    $image = $model->getImage();
    $sizes = $image->getSizes(); // Array. Original image sizes
    $sizes = $image->getSizesWhen('x500');
    echo '&lt;img width="'.$sizes['width'].'" height="'.$sizes['height'].'" src="'.$image->getUrl('x500').'" />';
    ```
5. Get original image

    ```
    $img = $model->getImage();
    echo $img->getPathToOrigin();
    ```

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

[](#installation)

1. Add Yii2-images to the require section of your composer.json file:

     ```
        {
             "require": {
                 "numkms/yii2-images": "dev-master"
             }
        }

    ```
2. run

     ```
       php composer.phar update

    ```
3. run migrate

     ```
     php yii migrate/up --migrationPath=@vendor/numkms/yii2-images/migrations

    ```
4. setup module

    ```
    'modules' => [
            'yii2images' => [
                'class' => 'numkms\yii2images\Module',
                //be sure, that permissions ok
                //if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
                'imagesStorePath' => 'images/store', //path to origin images
                'imagesCachePath' => 'images/cache', //path to resized copies
                'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
                'placeHolderPath' => '@webroot/images/placeHolder.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
                'imageCompressionQuality' => 100, // Optional. Default value is 85.
            ],
        ],
    ```
5. attach behaviour to your model (be sure that your model has "id" property)

    ```
        public function behaviors()
        {
            return [
                'image' => [
                    'class' => 'numkms\yii2images\behaviors\ImageBehave',
                    'fileAttribute' => 'mainimage',
                    'filesAttribute' => 'gallery',
                ]
            ];
        }
    ```

Thats all!

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 61.2% 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.

###  Release Activity

Cadence

Every ~281 days

Recently: every ~394 days

Total

11

Last Release

1502d ago

Major Versions

1.0.5 → 2.0.02017-12-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d8bf12ffc8de0f7c6fb8301b997056f758fcb7e13c8b6a71f868b99975dd123?d=identicon)[numkms](/maintainers/numkms)

---

Top Contributors

[![CostaRico](https://avatars.githubusercontent.com/u/3001018?v=4)](https://github.com/CostaRico "CostaRico (60 commits)")[![drtsb](https://avatars.githubusercontent.com/u/11088965?v=4)](https://github.com/drtsb "drtsb (6 commits)")[![numkms](https://avatars.githubusercontent.com/u/22604903?v=4)](https://github.com/numkms "numkms (6 commits)")[![synatree](https://avatars.githubusercontent.com/u/7294077?v=4)](https://github.com/synatree "synatree (4 commits)")[![andku83](https://avatars.githubusercontent.com/u/16827409?v=4)](https://github.com/andku83 "andku83 (4 commits)")[![rrhyne](https://avatars.githubusercontent.com/u/539268?v=4)](https://github.com/rrhyne "rrhyne (3 commits)")[![Enflow-io](https://avatars.githubusercontent.com/u/37901074?v=4)](https://github.com/Enflow-io "Enflow-io (2 commits)")[![vlykhoshva](https://avatars.githubusercontent.com/u/9845083?v=4)](https://github.com/vlykhoshva "vlykhoshva (2 commits)")[![CTOlet](https://avatars.githubusercontent.com/u/5058015?v=4)](https://github.com/CTOlet "CTOlet (2 commits)")[![evgenybukharev](https://avatars.githubusercontent.com/u/1708899?v=4)](https://github.com/evgenybukharev "evgenybukharev (2 commits)")[![webmayak](https://avatars.githubusercontent.com/u/642519?v=4)](https://github.com/webmayak "webmayak (1 commits)")[![arogachev](https://avatars.githubusercontent.com/u/8326201?v=4)](https://github.com/arogachev "arogachev (1 commits)")[![cgernert](https://avatars.githubusercontent.com/u/17023559?v=4)](https://github.com/cgernert "cgernert (1 commits)")[![cheaterBY](https://avatars.githubusercontent.com/u/3802712?v=4)](https://github.com/cheaterBY "cheaterBY (1 commits)")[![colinrlly](https://avatars.githubusercontent.com/u/4922632?v=4)](https://github.com/colinrlly "colinrlly (1 commits)")[![vollossy](https://avatars.githubusercontent.com/u/86642?v=4)](https://github.com/vollossy "vollossy (1 commits)")[![akim004](https://avatars.githubusercontent.com/u/7263218?v=4)](https://github.com/akim004 "akim004 (1 commits)")

---

Tags

imagesyii2storeimages storeyii2-imagesCosta numkms

### Embed Badge

![Health badge](/badges/numkms-yii2-images/health.svg)

```
[![Health](https://phpackages.com/badges/numkms-yii2-images/health.svg)](https://phpackages.com/packages/numkms-yii2-images)
```

###  Alternatives

[costa-rico/yii2-images

yii2 images module for storing images

16461.6k4](/packages/costa-rico-yii2-images)[liyunfang/yii2-upload-behavior

Upload behavior for Yii 2

161.7k](/packages/liyunfang-yii2-upload-behavior)

PHPackages © 2026

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