PHPackages                             silencesoft/slim-image-resize - 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. silencesoft/slim-image-resize

ActiveLibrary[Image &amp; Media](/categories/media)

silencesoft/slim-image-resize
=============================

Image Resize Middleware for Slim Framework

0.7.0(7y ago)024MITPHP

Since Nov 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/silencesoft/slim-image-resize)[ Packagist](https://packagist.org/packages/silencesoft/slim-image-resize)[ Docs](https://github.com/tuupola/slim-image-resize)[ RSS](/packages/silencesoft-slim-image-resize/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (4)Versions (5)Used By (0)

Image Resize Middleware for Slim 3
==================================

[](#image-resize-middleware-for-slim-3)

### Note

[](#note)

*This is an update to original project tuupola/slim-image-resize to work with slim 3.*

This middleware implements automatic image resizing based on image filename.

[![Author](https://camo.githubusercontent.com/b82ff4b35baf0280d673bfc9567e82f8eccf1e4ef1819a0ce4790231cd7d9322/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d40747575706f6c612d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/tuupola)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Build Status](https://camo.githubusercontent.com/a53ee6db78e641db32bce21397df7b8f71b55020a13bfeeabcad0412bbd54ef2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f747575706f6c612f736c696d2d696d6167652d726573697a652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/tuupola/slim-image-resize)[![HHVM Status](https://camo.githubusercontent.com/f4183511dfe8b1c735ea2799e2f96ce47d183046b917aebfef4fdd60f54d33ec/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f747575706f6c612f736c696d2d696d6167652d726573697a652e7376673f7374796c653d666c61742d737175617265)](http://hhvm.h4cc.de/package/tuupola/slim-image-resize)[![Coverage](https://camo.githubusercontent.com/b45864fa3240b9dcc5f120b6d2cf6d404f7d6b5a80ef50bba4f0f6f31824fe5f/687474703a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f747575706f6c612f736c696d2d696d6167652d726573697a652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/tuupola/slim-image-resize)

Install
-------

[](#install)

You can install latest version using [composer](https://getcomposer.org/).

```
$ composer require tuupola/slim-image-resize @dev

```

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

[](#configuration)

Configuration options are passed as an array. There are no mandatory parameters.

```
$app = new \Slim\Slim();
$app->add(new Slim\Middleware\ImageResize());
```

You can configure the allowed image extensions and cache folder. Cache folder must be writable by webserver process. Image quality applies only for jpg images. Example options shown below are also the default options used by the middleware.

```
$app = new \Slim\Slim();
$app->add(new Slim\Middleware\ImageResize([
    "extensions" => ["jpg", "jpeg", "png", "gif"],
    "cache" => "cache",
    "quality" => 90
]));
```

Caching
-------

[](#caching)

For caching to work you also must add the following to your [.htaccess](https://github.com/tuupola/slim-image-resize/blob/master/example/.htaccess) file. These rules should be added before Slim rewrite rules. Folder name must be the same you passed in as middleware configuration option. With caching rewrite rules in place only first request is served by PHP. All subsequent requests are served with static file from cache folder.

```
# Check for cached image in cache folder.
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /cache/$1 [L,QSA]

```

If your Slim application is installed in to a subfolder use the following rewrite rule instead. This example assumes the subfolder is called `example`.

```
RewriteBase /example

# Check for cached image in cache folder.
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{DOCUMENT_ROOT}/example/cache/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /example/cache/example/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

```

Usage
-----

[](#usage)

With middleware configured you can create different sizes of images by altering the filename.

```

```

HTML above will produce the following images.

[![Original](https://camo.githubusercontent.com/5d6499587d4aa60953e5b38f476b7a641ea2d783f5366c70c32879e18b117123/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722e6a7067)](https://camo.githubusercontent.com/5d6499587d4aa60953e5b38f476b7a641ea2d783f5366c70c32879e18b117123/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722e6a7067)[![400x200](https://camo.githubusercontent.com/6a4a3c1c01228b2b8114e27b51856b7415394ba209cae5a28cfcb138b29f0b19/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d343030783230302e6a7067)](https://camo.githubusercontent.com/6a4a3c1c01228b2b8114e27b51856b7415394ba209cae5a28cfcb138b29f0b19/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d343030783230302e6a7067)[![x200](https://camo.githubusercontent.com/cc7f87d04df48ac4d8e3df6d381511c537fb3e9bca7d4fa99dd574c6099e8c18/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d783230302e6a7067)](https://camo.githubusercontent.com/cc7f87d04df48ac4d8e3df6d381511c537fb3e9bca7d4fa99dd574c6099e8c18/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d783230302e6a7067)[![200x](https://camo.githubusercontent.com/e3dc2778d6e08a1e604d3986c8d56ed223826e34334869add14ec37467459a54/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d323030782e6a7067)](https://camo.githubusercontent.com/e3dc2778d6e08a1e604d3986c8d56ed223826e34334869add14ec37467459a54/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d323030782e6a7067)[![100x100](https://camo.githubusercontent.com/f346a0fdfb8cd14074b26f1503cab008a9352c039531cd8172e2beff6be94d74/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d313030783130302e6a7067)](https://camo.githubusercontent.com/f346a0fdfb8cd14074b26f1503cab008a9352c039531cd8172e2beff6be94d74/687474703a2f2f7777772e617070656c7369696e692e6e65742f696d672f76697065722d313030783130302e6a7067)

Security
--------

[](#security)

By default it is possible to create any size image. If images are also cached you should restrict which sizes middleware is allowed to create. Otherwise it is possible to make requests arbitary number of different sizes of images.

```
$app = new \Slim\Slim();
$app->add(new Slim\Middleware\ImageResize([
    "sizes" => ["400x200", "x200", "200x", "100x100"]
]));
```

If you have arbitary number of different sizes it is also possible to sign images with secret key.

```
$app->add(new Slim\Middleware\ImageResize([
    "secret" => "s11kr3t"
]));
```

You must include the signature in the image name.

```

```

Signature for above image was generated with following code.

```
$sha1 = sha1("400x200:s11kr3t");
$signature = substr($sha1, 0, 16);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~764 days

Total

3

Last Release

2676d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1beb9ceb94fa4ccdb9379568cad37b61bb689b237fe8bdd6b4d4ab293caea5e8?d=identicon)[silenceway](/maintainers/silenceway)

---

Top Contributors

[![tuupola](https://avatars.githubusercontent.com/u/21913?v=4)](https://github.com/tuupola "tuupola (41 commits)")

---

Tags

middlewareimageslim

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/silencesoft-slim-image-resize/health.svg)

```
[![Health](https://phpackages.com/badges/silencesoft-slim-image-resize/health.svg)](https://phpackages.com/packages/silencesoft-slim-image-resize)
```

###  Alternatives

[league/glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k51.2M116](/packages/league-glide)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M102](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[lasserafn/php-initial-avatar-generator

A package to generate avatars with initials for PHP

4374.2M13](/packages/lasserafn-php-initial-avatar-generator)[ctessier/nova-advanced-image-field

An advanced image field for Nova with cropping and resizing.

103548.4k1](/packages/ctessier-nova-advanced-image-field)[laravel-at/laravel-image-sanitize

A small but handy package to prevent malicious code execution coming into your application through uploaded image files.

26056.7k](/packages/laravel-at-laravel-image-sanitize)

PHPackages © 2026

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