PHPackages                             midnight/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. midnight/image

ActiveLibrary

midnight/image
==============

An image editing library

v0.1.1(12y ago)1335MITPHP

Since Sep 14Pushed 10y ago1 watchersCompare

[ Source](https://github.com/MidnightDesign/image)[ Packagist](https://packagist.org/packages/midnight/image)[ RSS](/packages/midnight-image/feed)WikiDiscussions master Synced 6d ago

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

midnight/image
==============

[](#midnightimage)

A small image editing library for PHP

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

[](#installation)

The library is available as a Composer package:

```
./composer.phar require midnight/image

```

Usage
-----

[](#usage)

Open an image:

```
$image = \Midnight\Image\Image::open('path/to/image.jpg');
```

Apply a filter:

```
$image->fit(array('width' => 150, 'height' => 200));
```

Get the new image after applying a filter:

```
$image->getFile();
```

Included filters
----------------

[](#included-filters)

The library comes with some pre-defined filters. They can be accessed by calling the filter name as a method of the image object. All filters accept an options array as their only argument. For example:

```
$options = array('foo' => true, 'bar' => 42);
$filtered_image = $image->filterName($options);
```

### `fit`

[](#fit)

Scales the image up or down to fit it inside a rectangle defined by the options `width` and `height`. It's the equivalent of CSS's `background-size: contain` property or Adobe InDesign's "Fit proportionally" option.

```
// $image has a size of 1500 by 2000 pixels
$thumbnail = $image->fit(array('width' => 200, 'height' => 200));
// $thumbnail is 150 x 200 pixels
```

### `fill`

[](#fill)

The `fill` filter fills a rectangle defined by the options `width` and `height`. It's the equivalent of CSS's `background-size: cover` property or Adobe InDesign's "Fill proportionally" option. It will most likely crop parts of the image.

```
// $image has a size of 1500 by 2000 pixels
$thumbnail = $image->fill(array('width' => 200, 'height' => 200));
// $thumbnail is 200 x 200 pixels, with cropped areas at the top and bottom
```

### `brighten`

[](#brighten)

Brightens the image. The only option is `amount`, which accepts an integer from -255 (which actually darkens the image) to 255.

```
$brightened = $image->brighten(array('amount' => 50));
```

### `desaturate`

[](#desaturate)

Desaturates the image. The only option is `amount`, which accepts an integer from -100 (which actually saturates image) to 100.

```
$desaturated = $image->desaturate(array('amount' => 25));
```

### `colorcast`

[](#colorcast)

Applies a color cast to the image. The available options are `color`, which accepts an instance of `Midnight\Color\Color` (actually `ColorInterface`) and `amount`, which accepts a value between 0 and 1.

```
// Apply a red color cast.
$red = new \Midnight\Color\Color(255, 0, 0);
$colorcasted = $image->colorcast(array('color' => $red, 'amount' => .2));
```

### `noise`

[](#noise)

Adds noise to the image. The only option available is `amount`.

```
$noisy = $image->noise(array('amount' => .1));
```

Adding a custom filter
----------------------

[](#adding-a-custom-filter)

You can easily add a custom filter:

```
class MyCustomFilter extends \Midnight\Image\Filter\AbstractGdFilter
{
    public function filter($image)
    {
        parent::filter($image);

        $cache = $this->getCache();
        if ($cache->exists($this)) {
            return Image::open($cache->getPath($this));
        }

        $im = $this->getGdImage();

        // Do stuff to GD image resource $im

        $image = $this->save($im);

        return $image;
    }
}
```

```
$plugin_manager = \Midnight\Image\ImagePluginManager::getInstance();
$plugin_manager->setService('myCustomFilter', 'MyCustomFilter');

// Use the filter
$filtered = \Midnight\Image\Image::open('file.jpg')->myCustomFilter();
```

###  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

Maturity55

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

Total

3

Last Release

3668d ago

Major Versions

v0.1.1 → 1.0.x-dev2016-05-02

### Community

Maintainers

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

---

Top Contributors

[![MidnightDesign](https://avatars.githubusercontent.com/u/743172?v=4)](https://github.com/MidnightDesign "MidnightDesign (35 commits)")

### Embed Badge

![Health badge](/badges/midnight-image/health.svg)

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

###  Alternatives

[mtymek/mt-mail

Zend Framework e-mail module. Using this library can easily create e-mail messages from PHTML templates (with optional layouts) and send them using configurable transports. Pluggable, EventManager-driven architecture allows you to customize every aspect of the process.

1839.2k3](/packages/mtymek-mt-mail)[zfbrasil/doctrine-money-module

Provide ZF2 integration between doctrine and mathiasverraes/money

1627.2k](/packages/zfbrasil-doctrine-money-module)[audeio/spotify-web-api

PHP library for the Spotify Web API

671.1k](/packages/audeio-spotify-web-api)

PHPackages © 2026

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