PHPackages                             pavlinter/yii2-display-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. [Image &amp; Media](/categories/media)
4. /
5. pavlinter/yii2-display-image

ActiveYii2-extension[Image &amp; Media](/categories/media)

pavlinter/yii2-display-image
============================

Yii2: Auto resize image

v1.1.4(9y ago)07851BSD 3-ClausePHP

Since Dec 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/pavlinter/yii2-display-image)[ Packagist](https://packagist.org/packages/pavlinter/yii2-display-image)[ RSS](/packages/pavlinter-yii2-display-image/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

Yii2 Display Image
==================

[](#yii2-display-image)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist pavlinter/yii2-display-image "dev-master"

```

or add

```
"pavlinter/yii2-display-image": "dev-master"

```

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

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

[](#configuration)

- Update config file

```
Yii::$container->set('pavlinter\display\DisplayImage', [
    //'returnSrc' => false,
    //'mode' => DisplayImage::MODE_INSET,
    //'defaultImage' => 'default.png',
    //'bgColor' => '000000',
    //'bgAlpha' => 0,
    //'cacheDir' => '@webroot/display-images-cache',
    //'cacheWebDir' => '@web/display-images-cache',
    //'innerCacheDir' => null, //example: 'cacheDirectory' takes precedence over [[cacheDir]]
    //'generalDefaultDir' => true
    //'defaultCategory' = 'default',
    'config' => [
        'items' => [
            'imagesWebDir' => '@web/display-images/items',
            'imagesDir' => '@webroot/display-images/items',
            'defaultWebDir' => '@web/display-images/default',
            'defaultDir' => '@webroot/display-images/default',
            'mode' => \pavlinter\display\DisplayImage::MODE_STATIC,
        ],
        'all' => [
            'imagesWebDir' => '@web/display-images/images',
            'imagesDir' => '@webroot/display-images/images',
            'defaultWebDir' => '@web/display-images/default',
            'defaultDir' => '@webroot/display-images/default',
            'mode' => \pavlinter\display\DisplayImage::MODE_OUTBOUND,
        ],
        'users' => [
            'imagesWebDir' => '@web/display-images/users',
            'imagesDir' => '@webroot/display-images/users',
            'defaultWebDir' => '@web/display-images/default',
            'defaultDir' => '@webroot/display-images/default',
            'mode' => 'ownMode',
            'bgColor' => 'ff0000',
            'resize' => function ($sender, $originalImage) {
                    /* @var $sender \pavlinter\display\DisplayImage */
                    /* @var $originalImage \Imagine\Imagick\Image */

                    $Box = new \Imagine\Image\Box($sender->width, $sender->height);
                    $newImage = $originalImage->thumbnail($Box);

                    $point = new \Imagine\Image\Point(0, 0);
                    $color = new \Imagine\Image\Color($sender->bgColor, $sender->bgAlpha);

                    return yii\imagine\Image::getImagine()->create($Box, $color)->paste($newImage, $point);
            },
        ],
    ]
]);
return [
  ...
];
```

Usage
-----

[](#usage)

```
use pavlinter\display\DisplayHelper;
use pavlinter\display\DisplayImage;

echo DisplayImage::widget([
    'width' => 120,
    'image' => '1.jpg',
    'category' => 'all',
    'cacheSeconds' => 'auto', //auto is default value. Rewrite image if modified file date is different
]);

echo DisplayImage::widget([ //subfolders image
    'width' => 120,
    'image' => '/subfolders/bg.jpg', // or subfolders/bg.jpg
    'category' => 'all',
]);

echo DisplayImage::widget([ //return resized Html::img
    'id_row' => 2,
    'width' => 100,
    'image' => 'desktopwal.jpg',
    'category' => 'items',
    'cacheSeconds' => 60 * 5, //rewrite resized image after 5 min
]);

echo DisplayImage::widget([ //return resized Html::img
    'width' => 100,
    'image' => '1.jpeg',
    'category' => 'all',
]);

echo DisplayImage::widget([ //return original Html::img
    'image' => '1.jpeg',
    'category' => 'all',
]);

echo DisplayImage::widget([
    'name' => 'newName',
    'width' => 100,
    'height' => 130,
    'image' => '334.gif',
    'category' => 'all',
]);

echo DisplayImage::widget([ //return default Html::img from items category
    'id_row' => 2,
    'width' => 100,
    'image' => 'rddddd',
    'category' => 'items',
]);

echo DisplayImage::widget([ //return default Html::img from all category
    'width' => 100,
    'height' => 130,
    'image' => 'aaaaaaaaa',
    'category' => 'all',
]);

echo DisplayImage::widget([ //return resized image path
    'returnSrc' => true,
    'width' => 100,
    'height' => 130,
    'image' => '334.gif',
    'category' => 'all',
]);

echo DisplayImage::widget([ //own resize mode
    'id_row' => 3,
    'width' => 100,
    'height' => 160,
    'image' => '3.jpeg',
    'category' => 'users',
]);

$images  = DisplayHelper::getImages(null, 'all', [ //or [[getImage()]] return first image
    'width' => 70,
    'height' => 70,
], [
    'minImages' => 6,
    'maxImages' => 10,
]);
/*Array(
    [1.jpeg] => /display-images-cache/all/\/70x70_outbound_000000_0/1.jpeg
    [334.gif] => /display-images-cache/all/\/70x70_outbound_000000_0/334.gif
    [360958.jpeg] => /display-images-cache/all/\/70x70_outbound_000000_0/360958.jpeg
    [926.jpg] => /display-images-cache/all/\/70x70_outbound_000000_0/926.jpg
    [0] => /display-images-cache/default/70x70_outbound_000000_0/default.png
    [1] => /display-images-cache/default/70x70_outbound_000000_0/default.png
)*/

$images  = DisplayHelper::getOriginalImages(null, 'all'); //or [[getOriginalImage()]] return first image

/*Array(
    [1.jpeg] => /display-images/images/\1.jpeg
    [334.gif] => /display-images/images/\334.gif
    [360958s.JPEG] => /display-images/images/\360958s.JPEG
    [926.jpg] => /display-images/images/\926.jpg
)*/

$images  = DisplayHelper::getImages(null, 'all', [ //or [[getImage()]] return first image
    'width' => 70,
    'height' => 70,
], [
    'return' => function ($data) {
        return $data; //required return string|array and image key
    },
]);

/*Array(
    [1.jpeg] => Array(
        [key] => 0
        [fullPath] => D:/localhost/wamp/www/my/test/yii2/advanced/frontend/web/display-images/images/\1.jpeg
        [dirName] => 1.jpeg
        [imagesDir] => D:/localhost/wamp/www/my/test/yii2/advanced/frontend/web/display-images/images/
        [imagesWebDir] => /display-images/images/
        [image] => 1.jpeg
        [display] => /display-images-cache/all/70x70_outbound_000000_0/1.jpeg
    )
    [334.gif] => Array(
        [key] => 1
        [fullPath] => D:/localhost/wamp/www/my/test/yii2/advanced/frontend/web/display-images/images/\334.gif
        [dirName] => 334.gif
        [imagesDir] => D:/localhost/wamp/www/my/test/yii2/advanced/frontend/web/display-images/images/
        [imagesWebDir] => /display-images/images/
        [image] => 334.gif
        [display] => /display-images-cache/all/70x70_outbound_000000_0/334.gif
    )
)*/

$clearItemId = DisplayHelper::clear('items', 2);
$clearItems = DisplayHelper::clear('items');

if ($clearItemId) {
    echo 'Clear item id 2!';
}
if ($clearItems) {
    echo 'Clear items category!';
}

$clearCacheDir = DisplayHelper::clearCacheDir(); //Only for outer directory cache [[innerCacheDir]]
if ($clearCacheDir) {
    echo 'Clear cache!';
}
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% 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 ~159 days

Recently: every ~186 days

Total

6

Last Release

3407d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa81148f518734b069ef57f90038de857b4022a2a1b8d59a0f75ccada1747409?d=identicon)[pavlinter](/maintainers/pavlinter)

---

Top Contributors

[![pavlinter](https://avatars.githubusercontent.com/u/6838002?v=4)](https://github.com/pavlinter "pavlinter (31 commits)")[![hooman-mirghasemi](https://avatars.githubusercontent.com/u/11981070?v=4)](https://github.com/hooman-mirghasemi "hooman-mirghasemi (1 commits)")

---

Tags

imageresizeyii2displaydisplayimagedisplay-image

### Embed Badge

![Health badge](/badges/pavlinter-yii2-display-image/health.svg)

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

###  Alternatives

[sadovojav/yii2-image-thumbnail

Yii2 image thumbnail component

2243.5k](/packages/sadovojav-yii2-image-thumbnail)[noam148/yii2-image-resize

A Yii2 component for resizing images (on the fly)

1044.9k7](/packages/noam148-yii2-image-resize)[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)
