PHPackages                             diarmuidie/imagerack - 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. diarmuidie/imagerack

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

diarmuidie/imagerack
====================

Simple PHP image processor and server.

v0.3.0(9y ago)5292MITPHPPHP &gt;=5.6

Since Aug 1Pushed 6y agoCompare

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

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

ImageRack
=========

[](#imagerack)

> Project repo for the [ImageRack PHP lib](https://github.com/diarmuidie/ImageRack-Kernel). Simple PHP image processor and server.

Developed by [Diarmuid](https://diarmuid.ie).

[![Build Status](https://camo.githubusercontent.com/37e42bffe2926d55c5053998097609517c2eb2edd11bf3be8829e92a946bf50f/68747470733a2f2f7472617669732d63692e6f72672f646961726d75696469652f496d6167655261636b2d4b65726e656c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/diarmuidie/ImageRack-Kernel)[![Coverage Status](https://camo.githubusercontent.com/2f442ec7b8b9d78f21b2dbab0d7ae23fc7006cdbbf6994bab581a6f507d15466/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f646961726d75696469652f496d6167655261636b2d4b65726e656c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/diarmuidie/ImageRack-Kernel?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/d9fa2d921e3ae0bed97adb6a7388782bf014500531dfb750be355b2bb8c940de/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33366639663866382d336337352d343934322d613130362d6339386265653236386164352f6d696e692e706e67)](https://insight.sensiolabs.com/projects/36f9f8f8-3c75-4942-a106-c98bee268ad5)

Features
--------

[](#features)

- Resizes images on the fly based on predefined user templates.
- Uses the [Intervention image library](https://github.com/Intervention/image) for easy image manipulation using GD or Imagick.
- Integrates with local or remote (Amazon S3, SFTP, Azure etc.) image stores using the [PHP League Flysystem](http://flysystem.thephpleague.com/) filesystem abstraction library.
- Ability to cache processed images so that subsequent requests are served quickly.
- SEO friendly and easy to use URLs i.e. `example.com//path/to/source/image.png`.
- Supports PNG/JPEG/GIF images.
- Adds `Cache-Control`, `ETag` and `Last_Modified` headers to response for better browser and CDN caching.

Usage
-----

[](#usage)

> *Sample Heroku Setup guide and code:* [diarmuid.ie/blog/setting-up-a-php-image-server-on-heroku](http://diarmuid.ie/blog/setting-up-a-php-image-server-on-heroku/).

To start a new project use the composer `create-project` command to install the ImageRack package in a named folder:

```
composer create-project diarmuidie/imagerack

```

Once the package is installed you can edit the contents of:

- `public/index.php` The main file that all requests are handled by.
- `bootstrap/dependencies.local.sample.php` Where the Flysystem and Intervention Image dependencies are configured.
- `templates/` Where your templates for resizing media will be stored.

### Server Configuration

[](#server-configuration)

#### Apache

[](#apache)

Ensure the `public/` directory is setup as your public-accessible DocumentRoot. The provided `.htaccess` file will redirect all requests to the ImageRack server.

#### Nginx

[](#nginx)

The Nginx configuration file should include the following information (in addition to any other settings you require):

```
root /some/folder/public;
index  index.php;

location ~ \.php$ {
    ...
    try_files $uri $uri/ /index.php?$args;
    ...
}

```

### Single Server Setup

[](#single-server-setup)

A single server deploy is the most straight forward configuration. Source images must be stored in the `storage/source` folder. Resized images will be cached in `storage/cache`.

### Multi-Server Setup

[](#multi-server-setup)

To use the ImageRack server in a multi-server environment (i.e. more than one web servers sitting behind a load ballancer) you must store the source and cache images in a distributed filesystem.

ImageRack comes with a sample configuration for using AWS S3 for this. To use this configuration you must make sure the Flysystem S3 adapter is installed:

```
composer require league/flysystem-aws-s3-v3

```

Then you can edit `public/index.php` to load the sample S3 dependencies:

```
$dependencies = require_once __DIR__.'/../bootstrap/dependencies.s3.sample.php';
```

You will also have to change the `bootstrap/dependencies.s3.sample.php` file to use your S3 Secret and Key and change the bucket names.

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

[](#configuration)

ImageRack allows you to configure the server in a number of ways:

### HTTP Cache Max Age

[](#http-cache-max-age)

You can overwrite the default http cache max age header value (30 days):

```
$server->setHttpCacheMaxAge(86000); // 86000 seconds = 1 day
```

Setting the cache duration to zero will disable the cache by setting a `Cache-Control:no-cache` header.

### Templates

[](#templates)

Templates are objects that define how an image should be manipulated. You can create multiple tempaltes to manipuate an image in different ways. Templates must implement the [Diarmuidie\\ImageRack\\Image\\TemplateInterface](https://github.com/diarmuidie/ImageRack-Kernel/blob/master/src/Image/TemplateInterface.php) interface. There is a [sample template](https://github.com/diarmuidie/ImageRack/blob/master/templates/Small.php) provided with ImageRack for resizing images to 320×240px.

After you create a new template it must be registered in the server:

```
$server->setTemplate(
    'large',
    function () {
        return new Templates\Large();
    }
);
```

The template name (`large` in this example) must be URL safe as it is used to access images using this template i.e. `example.com/large/path/to/image.jpg`.

### Not Found Response

[](#not-found-response)

You can set an optional "not found" response. By default a 404 header will be sent with the body "File not found". However this can be modified using the `setNotFound()` method:

```
$server->setNotFound(function ($response) {

    // Edit the response as required.
    // For example here we cahnge the content
    $response->setContent('Image not found.');

    // Return the modified response
    return $response;

});
```

`$response` is an instance of `Symfony\Component\HttpFoundation\Response`. See the [Symfony HTTP-Foundation docs](http://symfony.com/doc/current/components/http_foundation/introduction.html#response) for more info on what you can do with the response.

### Error Response

[](#error-response)

You can set an optional "error" response. By default a 500 header will be sent with the body "There has been a problem serving this request". However this can be modified using the `setError()` method:

```
$server->setError(function ($response, $exception) {

    // Edit the response as required.
    // For example here we add the exception message to the content
    $response->setContent('An internal error occurred. ' . $exception->getMessage());

    // Return the modified response
    return $response;

});
```

`$exception` is an instance of the caught exception.

`$response` is an instance of `Symfony\Component\HttpFoundation\Response`. See the [Symfony HTTP-Foundation docs](http://symfony.com/doc/current/components/http_foundation/introduction.html#response) for more info on what you can do with the response.

Changelog
---------

[](#changelog)

### Version 0.1.0 (29 March 2015)

[](#version-010-29-march-2015)

- Initial commit.

### Version 0.1.1 (5 August 2015)

[](#version-011-5-august-2015)

- Require 0.2.0 release of ImageRack.

### Version 0.2.0 (9 August 2015)

[](#version-020-9-august-2015)

- Default to GD image library.

### Version 0.2.1 (11 August 2015)

[](#version-021-11-august-2015)

- Doc tidy up an improvements to examples.

### Version 0.3.0 (5 March 2017)

[](#version-030-5-march-2017)

- Require 0.4.0 release of ImageRack (PHP &gt;= 5.6)

Authors
-------

[](#authors)

- [Diarmuid](https://diarmuid.ie)

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2017 Diarmuid

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Total

5

Last Release

3361d ago

PHP version history (2 changes)v0.2.0PHP &gt;=5.4

v0.3.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/8478c1cc380ffdafb9739f9467cd35664307ac413f8baa7fa6f690241c7528f8?d=identicon)[diarmuidie](/maintainers/diarmuidie)

---

Top Contributors

[![diarmuidie](https://avatars.githubusercontent.com/u/707037?v=4)](https://github.com/diarmuidie "diarmuidie (50 commits)")

---

Tags

image-manipulationphpphp-image-processorimageserverresize

### Embed Badge

![Health badge](/badges/diarmuidie-imagerack/health.svg)

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

###  Alternatives

[intervention/image

PHP Image Processing

14.3k194.3M2.2k](/packages/intervention-image)[gumlet/php-image-resize

PHP class to re-size and scale images

1.2k5.7M54](/packages/gumlet-php-image-resize)[masterexploder/phpthumb

A library for manipulating images in PHP.

981751.7k17](/packages/masterexploder-phpthumb)[sybio/image-workshop

Powerful PHP class using GD library to work easily with images including layer notion (like Photoshop or GIMP)

860918.1k11](/packages/sybio-image-workshop)[intervention/image-laravel

Laravel Integration of Intervention Image

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

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)

PHPackages © 2026

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