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

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

alex290/yii2-images
===================

yii2 images module for storing images

1.0.6(2y ago)31.1k33BSD-3-ClausePHP

Since Feb 17Pushed 2y ago2 watchersCompare

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

READMEChangelog (5)Dependencies (5)Versions (6)Used By (3)

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

[](#yii2-images)

Модуль поддерживает библиотеки Imagick и GD, вы можете настроить его в настройках модуля.

Пример использования:
---------------------

[](#пример-использования)

```
$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);
}
```

Детали
------

[](#детали)

1. Получить изображения

    ```
    $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. Удалить изображение / изображения

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

    $model->removeImages(); //will remove all images of this model
    ```
3. Установить основное изображение

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

    foreach($model->getImages() as $img){
        if($img->getPrimaryKey() == $ourId){
            $model->setMainImage($img);//will set current image main
        }
    }
    ```
4. Получить размеры изображения

    ```
    $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. Получить оригинальное изображение

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

Установка
---------

[](#установка)

1. Запустить

    ```
     php composer.phar require --prefer-dist alex290/yii2-images "*"

    ```

    или добавить

    ```
     "alex290/yii2-images": "*"

    ```

    в секцию require вашего `composer.json` файла.
2. run

     ```
       php composer.phar update

    ```
3. run migrate

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

    ```
4. Настройка модуля

    ```
    'modules' => [
            'yii2images' => [
                'class' => 'alex290\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' => 'alex290\yii2images\behaviors\ImageBehave',
                ]
            ];
        }
    ```

Thats all!

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~324 days

Total

5

Last Release

985d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/35fd7f2d7b8be6fef06a2c6aee576282f55559098fd5d6075a7fedc80df48f34?d=identicon)[alex290](/maintainers/alex290)

---

Top Contributors

[![alex290](https://avatars.githubusercontent.com/u/13647764?v=4)](https://github.com/alex290 "alex290 (2 commits)")

---

Tags

imagesyii2storeimages storeyii2-imagesCosta alex290

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/alex290-yii2-images/health.svg)](https://phpackages.com/packages/alex290-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)
