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

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

despark/image-purify
====================

Image purifier - A ps/image-optimizer fork

v0.1.8(6y ago)63.0k↓100%2MITPHPPHP &gt;=7.0CI failing

Since May 30Pushed 6y ago6 watchersCompare

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

READMEChangelog (4)Dependencies (7)Versions (9)Used By (0)

[![Build Status](https://camo.githubusercontent.com/588e83f79f77e21e61cbbe678c4d686d0014e1597848a7ef4799d41bf652bc81/68747470733a2f2f7472617669732d63692e6f72672f6465737061726b2f696d6167652d7075726966792e737667)](https://travis-ci.org/despark/image-purify)[![Latest Stable Version](https://camo.githubusercontent.com/0d8ad08b3f7d8de48a8f13019d2c0d001e1b2a52fd6d61218f4e5b8ee3a20c56/68747470733a2f2f706f7365722e707567782e6f72672f6465737061726b2f696d6167652d7075726966792f762f737461626c65)](https://packagist.org/packages/despark/image-purify)[![Total Downloads](https://camo.githubusercontent.com/d0aed24b4ad1011ba4bba07dd2c48874b4d7f4b61fb5b01a36cbdf6064b1acf4/68747470733a2f2f706f7365722e707567782e6f72672f6465737061726b2f696d6167652d7075726966792f646f776e6c6f616473)](https://packagist.org/packages/despark/image-purify)[![License](https://camo.githubusercontent.com/d02770369065329262503aba1832569e6057d7d2145cbdaab111dbc53ececbfc/68747470733a2f2f706f7365722e707567782e6f72672f6465737061726b2f696d6167652d7075726966792f6c6963656e7365)](https://packagist.org/packages/despark/image-purify)

About Image Purifier
--------------------

[](#about-image-purifier)

Image optimization library inspired by [psliwa/image-optimizer](https://github.com/psliwa/image-optimizer). It allows processing image paths by automatically detecting the file type and feeding it to certain chain.

Libraries
---------

[](#libraries)

Currently we support the following server side libraries for optimization. You must install them on your server in order to use this library. Of you want to add more you can do so by using your own command.

- [mozjpeg](https://github.com/mozilla/mozjpeg)
- [pngquant](https://pngquant.org/)
- [optipng](http://optipng.sourceforge.net/)
- [giflossy](https://github.com/pornel/giflossy)\*

*\*Giflossy is a fork of [gifsicle](https://www.lcdf.org/gifsicle/) so you can use the main library by excluding the --lossy argument [(see options)](#factory-options)*

Exmple Usage
------------

[](#exmple-usage)

Initialize the purifier with sensible defaults

```
$options = [];
$purifierFactory = new ImagePurifierFactory($options, $logger);

$purifier = $purifierFactory->create();
$purifier->purify('path/to/image.png');
```

The `ImagePurifierFactory` takes two optional arguments `$options` and `$logger`.

#### Factory Options

[](#factory-options)

This is an anatomy of an factory option

```
[
// This is the chain config. You can define your own chain and feed it commands
'chains' => [
    JpegChain::class => [ // Chains must be real classes which contains commands to be executed
        'commands' => [
            'mozJpeg' => [
                'bin' => 'cjpeg', // Path to the executable. The lbrary tries to resolve it itself
                'arguments' => ['-optimize', '-progressive'], // What arguments to run
                'customClass' => MozJpeg::class, // If you want you can give custom class that must implements our CommandInterface
            ],
        ],
        'first_only' => false, // If this is true only the first command will be executed
    ],
    ...
],
'suppress_errors' => false // If set to true exceptions will be catched and only logs will be written,
]);
```

#### Logger

[](#logger)

You can pass custom logger to the `ImagePurifierFactory` which must implement `Psr\Log\LoggerInterface`

Good to know
------------

[](#good-to-know)

Pngquant will exit with code `98` if the file was already optimized (at least this is what we experienced on tests). This is for you to handle if the errors are not suppressed. If this happens we throw CommandException with special code `98`\*In general it is a good idea to make sure files are optimized only once. Example:

```
try{
    $purifier->purify($filePath);
}catch(CommandException $e){
    if($e->getCode() === 98){
        // handle png quant already processed
    }
}
```

Advanced usage
--------------

[](#advanced-usage)

To be done

Tests and coverage
------------------

[](#tests-and-coverage)

You can run the tests by executing

```
composer test
```

We aim at 100% test coverage.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81% 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 ~146 days

Recently: every ~253 days

Total

8

Last Release

2241d ago

### Community

Maintainers

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

---

Top Contributors

[![lsimeonov](https://avatars.githubusercontent.com/u/17702047?v=4)](https://github.com/lsimeonov "lsimeonov (17 commits)")[![ageshev](https://avatars.githubusercontent.com/u/9364161?v=4)](https://github.com/ageshev "ageshev (3 commits)")[![danmichaelo](https://avatars.githubusercontent.com/u/434495?v=4)](https://github.com/danmichaelo "danmichaelo (1 commits)")

---

Tags

giflossygifsicleimage-optimizationmozjpegoptimizationoptipngphp7imagecompressionimage-optimizeroptimizationpngquantMozJPEGoptipnggifsiclegiflossy

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ps/image-optimizer

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

9341.7M25](/packages/ps-image-optimizer)[spatie/image-optimizer

Easily optimize images using PHP

2.9k71.3M109](/packages/spatie-image-optimizer)[phpbench/phpbench

PHP Benchmarking Framework

2.0k13.0M627](/packages/phpbench-phpbench)[gtuk/image-optimizer

PHP image optimizer for png, jpeg and gif files. It uses mozjpeg, pngquant and gifsicle for the optimization process

161.6k](/packages/gtuk-image-optimizer)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[spatie/image

Manipulate images with an expressive API

1.4k54.4M137](/packages/spatie-image)

PHPackages © 2026

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