PHPackages                             lireincore/imgcache - 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. [Caching](/categories/caching)
4. /
5. lireincore/imgcache

ActiveLibrary[Caching](/categories/caching)

lireincore/imgcache
===================

Image cache

0.6.0(6y ago)63.1k2MITPHPPHP &gt;=7.2.0

Since Apr 26Pushed 6y ago3 watchersCompare

[ Source](https://github.com/lireincore/imgcache)[ Packagist](https://packagist.org/packages/lireincore/imgcache)[ Docs](https://github.com/lireincore/imgcache)[ RSS](/packages/lireincore-imgcache/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (10)Used By (2)

Image cache
===========

[](#image-cache)

[![Latest Stable Version](https://camo.githubusercontent.com/fcbae098eb284de7b416032581468793528aa50a4839116a27fb78fef3084ee9/68747470733a2f2f706f7365722e707567782e6f72672f6c697265696e636f72652f696d6763616368652f762f737461626c65)](https://packagist.org/packages/lireincore/imgcache)[![Total Downloads](https://camo.githubusercontent.com/8156565baf6a7221155d1eac4acdec9ed3214a36aeb66a72b6f31e47384b0c29/68747470733a2f2f706f7365722e707567782e6f72672f6c697265696e636f72652f696d6763616368652f646f776e6c6f616473)](https://packagist.org/packages/lireincore/imgcache)[![License](https://camo.githubusercontent.com/39828497b99625b1a097fad23aa317835391aa8b48e1fb08ece349863a5b4636/68747470733a2f2f706f7365722e707567782e6f72672f6c697265696e636f72652f696d6763616368652f6c6963656e7365)](https://packagist.org/packages/lireincore/imgcache)

About
-----

[](#about)

Adds caching capabilities to the package [lireincore/image](https://github.com/lireincore/image)

Also, you can use [lireincore/yii2-imgcache](https://github.com/lireincore/yii2-imgcache) extension that integrates this package with Yii2 framework.

And, you can use [lireincore/LireinCoreImgCacheBundle](https://github.com/lireincore/LireinCoreImgCacheBundle) bundle that integrates this package with Symfony framework.

Install
-------

[](#install)

Add the `"lireincore/imgcache": "^0.6"` package to your `require` section in the `composer.json` file

or

```
$ php composer.phar require lireincore/imgcache
```

Usage
-----

[](#usage)

```
use LireinCore\ImgCache\ImgCache;

$config = [
    // graphic library for all presets: imagick, gd, gmagick
    // (by default, tries to use: imagick->gd->gmagick)
    'driver' => 'gmagick',

    // original images source directory for all presets
    'srcdir' => '/path/to/my/project/uploads',

    // thumbs destination directory for all presets (required)
    // (to access the thumbs from the web they should be in a directory accessible from the web)
    'destdir' => '/path/to/my/project/www/thumbs',

    // web directory for all presets
    'webdir' => '/path/to/my/project/www',

    // base url for all presets
    'baseurl' => 'https://www.mysite.com',

    // quality of save jpeg images for all presets: 0-100 (default: 75)
    'jpeg_quality' => 80,

    // compression level of save png images for all presets: 0-9 (default: 7)
    'png_compression_level' => 8,

    // compression filter of save png images for all presets: 0-9 (default: 5)
    'png_compression_filter' => 6,

    // formats convert map for all presets
    // supported formats for destination images: jpeg, png, gif, wbmp, xbm
    // (default: ['jpeg' => 'jpeg', 'png' => 'png', 'gif' => 'gif', 'wbmp' => 'wbmp', 'xbm' => 'xbm',
    // '*' => 'png'])
    'convert_map' => [
        // source format => destination format
        'gif,wbmp' => 'png', // gif and wbmp to png
        '*' => 'jpeg'        // all others to jpeg
    ],

    // plug for all presets (used if original image is not available)
    'plug' => [
        // absolute path to plug
        'path' => '/path/to/my/project/assets/plug.png',

        // apply preset effects and postprocessors to plug? (default: false)
        'process' => true,
    ],

    // define custom image class for all presets (which implements \LireinCore\Image\Manipulator interface)
    // (default: \LireinCore\Image\Manipulators\Imagine)
    'image_class' => '\Foo\Bar\MyImageClass',

    // register custom effects or override default effects
    // (default effects: crop, cover, resize, scale_up, scale_down, scale, rotate, overlay,
    // flip, fit, blur, gamma, grayscale, negative, text)
    'effects_map' => [
        // effect => class (which implements \LireinCore\Image\Effect interface)
        'myeffect1' => '\Foo\Bar\MyEffect1',
        'myeffect2' => '\Foo\Bar\MyEffect2'
    ],

    // register custom postprocessors or override default postprocessors
    // (default postprocessors: jpegoptim, optipng, pngquant)
    'postprocessors_map' => [
        // postprocessor => class (which implements \LireinCore\Image\PostProcessor interface)
        'my_postprocessor1' => '\Foo\Bar\MyPostProcessor1',
        'my_postprocessor2' => '\Foo\Bar\MyPostProcessor2'
    ],

    // postprocessors list
    'postprocessors' => [
        [
            // postprocessor type
            'type' => 'jpegoptim',
            // postprocessor params
            'params' => [
                'path' => '/path/to/jpegoptim', // custom path to postprocessor binary
                                                // (default: '/usr/bin/jpegoptim')
                'quality' => 75,                // for example: 0-100, 0 - worst | 100 - best
                                                // (default: 85)
                'strip_all' => false,           // remove all metadata (Comments, Exif, IPTC, ICC, XMP)
                                                // (default: true)
                'progressive' => false          // convert to progressive jpeg (default: true)
            ]
        ],
        [
            // postprocessor type
            'type' => 'optipng',
            // postprocessor params
            'params' => [
                'path' => '/path/to/optipng', // custom path to postprocessor binary
                                              // (default: '/usr/bin/optipng')
                'level' => 5,                 // for example: 0-7, 0 - max compression speed |
                                              // 7 - max compression size (default: 2)
                'strip_all' => false          // remove all metadata (default: true)
            ]
        ]
    ],

    // presets list
    'presets' => [
        // preset 'origin'
        'origin' => [
            // effects list
            'effects' => [
                [
                    // effect type
                    'type' => 'overlay',
                    // effect params
                    'params' => [
                        'path' => '/path/to/watermark.png', // path to overlay
                        'opacity' => 80,        // overlay opacity, for example: 0-100,
                                                // 0 - fully transparent | 100 - not transparent
                                                // (default: 100) (not supported in gmagick)
                        'offset_x' => 'right',  // overlay horizontal offset, for example: 100 | 20% |
                                                // center | left | right  (default: right)
                        'offset_y' => 'bottom', // overlay vertical offset, for example: 100 | 20% |
                                                // center | top | bottom  (default: bottom)
                        'width' => '50%',       // overlay width, for example: 100 | 20% - change
                                                // overlay image width
                                                // (% - relative to the background image)
                                                // (default: original size)
                        'height' => '50%'       // overlay height, for example: 100 | 20% - change
                                                // overlay image height
                                                // (% - relative to the background image)
                                                // (default: original size)
                    ]
                ],
            ],

            // you can override certain options for this preset

            // graphic library for preset 'origin'
            'driver' => 'gd',

            // original images source directory for preset 'origin'
            'srcdir' => '/path/to/my/project/backend/uploads',

            // thumbs destination directory for preset 'origin'
            // (to access the thumbs from the web they should be in a directory accessible from the web)
            'destdir' => '/path/to/my/project/backend/www/thumbs',

            // web directory for preset 'origin'
            'webdir' => '/path/to/my/project/backend/www',

            // base url for preset 'origin'
            'baseurl' => 'https://admin.mysite.com',

            // quality of save jpeg images for preset 'origin'
            'jpeg_quality' => 100,

            // compression level of save png images for preset 'origin'
            'png_compression_level' => 9,

            // compression filter of save png images for preset 'origin'
            'png_compression_filter' => 9,

            // plug for preset 'origin' (used if original image is not available)
            'plug' => [
                'path' => '/path/to/my/project/backend/assets/plug_origin.png',
            ],

            // define custom image class for preset 'origin'
            // (which implements \LireinCore\Image\Manipulator interface)
            'image_class' => '\Foo\Bar\MyOriginImage',

            // postprocessors list for preset 'origin'
            'postprocessors' => [
                [
                    // postprocessor type
                    'type' => 'pngquant',
                    // postprocessor params
                    'params' => [
                        'path' => '/path/to/pngquant', // custom path to postprocessor binary
                                                       // (default: '/usr/bin/pngquant')
                        'quality' => 75,               // for example: 0-100, 0 - worst | 100 - best
                                                       // (default: 85)
                    ]
                ]
            ],
        ],

        // preset 'content_preview'
        'content_preview' => [
            'effects' => [
                // first effect
                [
                    'type' => 'scale_up',
                    'params' => [
                        'max_width' => '500',    // for example: 100 | 20% (default: auto)
                        'max_height' => '500',   // for example: 100 | 20% (default: auto)
                        'allow_increase' => true // increase if image is less (default: false)
                    ]
                ],
                // second effect
                [
                    'type' => 'crop',
                    'params' => [
                        'offset_x' => '50%', // for example: 100 | 20% | center | left | right
                                             // (default: left)
                        'offset_y' => '50%', // for example: 100 | 20% | center | top | bottom
                                             // (default: top)
                        'width' => '50%',    // for example: 100 | 20% (default: auto)
                        'height' => '50%'    // for example: 100 | 20% (default: auto)
                    ]
                ],
                // third effect
                [
                    'type' => 'gamma',
                    'params' => [
                        'correction' => 0.8 // gamma correction (0.0-1.0)
                    ]
                ],
                // fourth effect
                [
                    'type' => 'blur',
                    'params' => [
                        'sigma' => 3 // standard deviation
                    ]
                ]
            ],
            // formats convert map for preset 'content', extend convert map for all presets
            'convert_map' => [
                'xbm' => 'png', // xbm to png
                'gif' => 'jpeg'
            ],
            'plug' => [
                // url to get the plug from a third-party service
                'url' => 'http://placehold.it/100x100'
            ],
        ],

        // preset 'test'
        'test' => [
            'effects' => [
                [
                    'type' => 'grayscale',
                ],
                [
                    'type' => 'fit',
                    'params' => [
                        'offset_x' => 'center',  // for example: 100 | 20% | center | left | right
                                                 // (default: center)
                        'offset_y' => 'center',  // for example: 100 | 20% | center | top | bottom
                                                 // (default: center)
                        'width' => '200',        // for example: 100 | 20% (default: auto)
                        'height' => '90',        // for example: 100 | 20% (default: auto)
                        'bgcolor' => '#f00',     // background color, for example: '#fff' or '#ffffff' -
                                                 // hex | '50,50,50' - rgb | '50,50,50,50' - cmyk
                                                 // (default: #fff)
                        'bgtransparency' => 50,  // background transparency, for example: 0-100,
                                                 // 0 - not transparent | 100 - fully transparent
                                                 // (default: 0) (not supported in gmagick)
                        'allow_increase' => true // increase if image is less (default: false)
                    ]
                ]
                [
                    'type' => 'text',
                    'params' => [
                        'text' => 'Hello word!',   // text for writing
                        'font' => '/path/to/font', // font name or absolute path to the font file,
                                                   // for example: Verdana (default: Times New Roman)
                        'offset_x' => '5%',        // for example: 100 | 20% (default: 0)
                        'offset_y' => '10',        // for example: 100 | 20% (default: 0)
                        'size' => 14,              // font size, for example: 14 (default: 12)
                        'color' => '#000',         // font color, for example: '#fff' or '#ffffff' - hex |
                                                   // '50,50,50' - rgb | '50,50,50,50' - cmyk
                                                   // (default: #fff)
                        'opacity' => 50,           // font opacity, for example: 0-100,
                                                   // 0 - fully transparent | 100 - not transparent
                                                   // (default: 100)
                        'angle' => 30,             // in degrees, for example: 90 (default: 0)
                        'width' => '90%',          // for example: 100 | 20% - text box width
                                                   // (% - relative to the background image)
                                                   // (default: none)
                    ]
                ]
            ],
        ],

        // preset 'test2'
        'test2' => [
            'effects' => [
                [
                    'type' => 'negative'
                ],
                [
                    'type' => 'flip',
                    'params' => [
                        'mode' => 'horizontal' // for example: vertical | horizontal | full
                    ]
                ],
                [
                    'type' => 'resize',
                    'params' => [
                        'width' => '100', // 100 | 20% (default: auto)
                        'height' => '100' // 100 | 20% (default: auto)
                    ]
                ],
                [
                    'type' => 'rotate',
                    'params' => [
                        'angle' => 90,         // angle in degrees
                        'bgcolor' => '#f00',   // background color, for example: '#fff' or '#ffffff' -
                                               // hex | '50,50,50' - rgb | '50,50,50,50' - cmyk
                                               // (default: #fff)
                        'bgtransparency' => 70 // background transparency, for example: 0-100,
                                               // 0 - not transparent | 100 - fully transparent
                                               // (default: 0) (not supported in gmagick)
                    ]
                ],
                [
                    'type' => 'scale',
                    'params' => [
                        'ratio' => '200%', // (for example: 0.5 | 50%)
                    ]
                ],
            ],
        ],

        // preset 'test3'
        'test3' => [
            'effects' => [
                [
                    'type' => 'cover',
                    'params' => [
                        'offset_x' => 'left', // for example: 100 | 20% | center | left | right
                                              // (default: center)
                        'offset_y' => 'top',  // for example: 100 | 20% | center | top | bottom
                                              // (default: center)
                        'width' => '200',     // for example: 100 | 20% (default: auto)
                        'height' => '90',     // for example: 100 | 20% (default: auto)
                    ]
                ]
            ],
        ],
    ],
];

$imgcache = new ImgCache($config);

// get thumb path for image '{srcdir}/user/image.jpg' (preset 'origin')
$thumbPath = $imgcache->path('user/image.jpg', 'origin');

// $thumbPath === '{destdir}/presets/origin/user/image.jpg'
// if the source image is not found
// $thumbPath === '{destdir}/plugs/origin/plug_origin.png'

// get thumb relative url for image '{srcdir}/blog/image.jpg' (preset 'content_preview')
$thumbRelUrl = $imgcache->url('blog/image.jpg', 'content_preview');
// $thumbRelUrl === '/thumbs/presets/content_preview/blog/image.jpg'

// get thumb absolute url for image '{srcdir}/news/image.jpg' (preset 'test')
$thumbAbsUrl = $imgcache->url('news/image.jpg', 'test', true);
// $thumbAbsUrl === '{baseurl}/thumbs/presets/test/news/image.jpg'

// clear preset thumbs
$imgcache->clearCache('presetName');

// clear all presets thumbs
$imgcache->clearCache();
```

License
-------

[](#license)

This project is licensed under the MIT License - see the [License File](LICENSE) file for details

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.6% 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 ~70 days

Recently: every ~113 days

Total

9

Last Release

2423d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.4

0.5.0PHP &gt;=7.2.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21308223?v=4)[lireincore](/maintainers/lireincore)[@lireincore](https://github.com/lireincore)

---

Top Contributors

[![lireincore](https://avatars.githubusercontent.com/u/21308223?v=4)](https://github.com/lireincore "lireincore (22 commits)")[![sgworker](https://avatars.githubusercontent.com/u/20991976?v=4)](https://github.com/sgworker "sgworker (4 commits)")

---

Tags

cacheeffectimagephppresetresizethumbthumbnailimageresizecachethumbpreseteffect

### Embed Badge

![Health badge](/badges/lireincore-imgcache/health.svg)

```
[![Health](https://phpackages.com/badges/lireincore-imgcache/health.svg)](https://phpackages.com/packages/lireincore-imgcache)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k86.9M2.2k](/packages/symfony-symfony)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k365.0M3.1k](/packages/symfony-cache)[web-auth/webauthn-lib

FIDO2/Webauthn Support For PHP

1237.8M121](/packages/web-auth-webauthn-lib)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

51390.8k3](/packages/web-auth-webauthn-framework)[eliashaeussler/cache-warmup

Composer package to warm up website caches, based on a given XML sitemap

75419.2k9](/packages/eliashaeussler-cache-warmup)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)

PHPackages © 2026

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