PHPackages                             rvdlee/zf-image-optimiser - 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. rvdlee/zf-image-optimiser

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

rvdlee/zf-image-optimiser
=========================

A package that allows you optimise images. To reduce in size with very slight quality loss.

0.1.1(6y ago)0146MITPHPPHP ^7.2 || ^7.3CI failing

Since Oct 11Pushed 6y ago1 watchersCompare

[ Source](https://github.com/rvdlee/zf-image-optimizer)[ Packagist](https://packagist.org/packages/rvdlee/zf-image-optimiser)[ Docs](https://thoughtforcoding.com/)[ RSS](/packages/rvdlee-zf-image-optimiser/feed)WikiDiscussions master Synced yesterday

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

ZF3 Package to optimize images
==============================

[](#zf3-package-to-optimize-images)

[![Latest Version on Packagist](https://camo.githubusercontent.com/de9604de4cff911f645deb2bbc898a035fd0478eef79a24c36086431bcbfa5d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7276646c65652f7a662d696d6167652d6f7074696d697365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rvdlee/zf-image-optimiser)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fafea80046e4b49976a101bff954374ed4c79cc6ff4856206496fe1f74b1440d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7276646c65652f7a662d696d6167652d6f7074696d697365722f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/rvdlee/zf-image-optimiser)[![Total Downloads](https://camo.githubusercontent.com/a0a9f06f8daf96524fd4c9f35b6ccd51d7adc8bff2a50941e20d7410610fc412/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7276646c65652f7a662d696d6167652d6f7074696d697365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rvdlee/zf-image-optimiser)[![GitHub license](https://camo.githubusercontent.com/94bf837cf2f6fd4bc70f3e280886f4fe7961ecb2e32ad32a6abc0b847b31d254/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f45706963536f6674776f726b732f70656c6963616e2d707269736d6a732e737667)](https://github.com/EpicSoftworks/pelican-prismjs/blob/master/LICENSE)[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.me/epicsoftworks)

This is a image optimiser package. I've written this with ZF3 in mind, everything is written with configuration over convention in mind. Highly extendible and easy in use. Currently supporting Gifsicle, JpegOptim, Optipng and pngquant2.

This package provides the following ways of converting:

- Through the commandline
- InputFilter
- Sevice

Usage
-----

[](#usage)

To get started you need to configure your validation chain. The validation chain acts as a validator for the files that are due to processing. There is a [provided config dist file](https://github.com/rvdlee/zf-image-optimiser/blob/master/config/local.config.php.dist) with all the configuration you need to get started.

The validator chain will require the standard zend validators to verify if the file is suitable to be handled by these adapters. It will look like something like this.

```
# ... config use statements

return [
    'rvdlee' => [
        'zf-image-optimiser' => [
            # ... Other adapters
            Pngquant2::class => [
                'binary-options'  => [
                    '--verbose',
                    '--force',
                    '--strip',
                    '--speed 1',
                    '--quality=75-100',
                ],
                'validator-chain' => [
                    ['name' => IsImage::class],
                    [
                        'name'    => Extension::class,
                        'options' => [
                            'case'       => false,
                            'extensions' => 'png',
                        ],
                    ],
                    [
                        'name'    => MimeType::class,
                        'options' => [
                            'mimeType' => ['image/png'],
                        ],
                    ],
                ],
            ],
            'enabled'        => [
                # ... Other adapters
                Pngquant2::class,
            ],
        ],
    ],
];
```

InputFilters
------------

[](#inputfilters)

The standard file handling through forms is done with InputFilters in Zend, the InputFilter in this package allows you to save or overwrite the uploaded image. By default behaviour it will overwrite to be more inline with other file handling filters.

Here a example of an InputFilter in a FormInputFilter file using the ImageOptimiser filter to reduce filesize.

```
# ... Other InputFilters

$this->add(
    [
        'type'       => FileInput::class,
        'name'       => 'image',
        'required'   => false,
        'filters'    => [
            [
                'name'    => RenameUpload::class,
                'options' => [
                    'target'             => ,
                    'useUploadName'      => true,
                    'useUploadExtension' => true,
                    'overwrite'          => false,
                    'randomize'          => false,
                ],
            ],
            ['name' => ImageOptimiser::class],
        ],
        'validators' => [
            ['name' => IsImage::class],
            [
                'name'    => FilesSize::class,
                'options' => [
                    'min' => '4kB',
                    'max' => '8MB',
                ],
            ],
            [
                'name'    => Extension::class,
                'options' => [
                    'case'       => false,
                    'extensions' => 'jpg,png',
                ],
            ],
            [
                'name'    => MimeType::class,
                'options' => [
                    'mimeType' => [
                        'image/jpeg',
                        'image/png',
                    ],
                ],
            ],
            [
                'name'    => ImageSize::class,
                'options' => [
                    'minWidth'  => 128,
                    'minHeight' => 128,
                    'maxWidth'  => 4096,
                    'maxHeight' => 4096,
                ],
            ],
        ],
    ]
);

# ... Other InputFilters
```

Commandline
-----------

[](#commandline)

The commandline controller is nothing more than a wrapper for the service calling `optimise()`. You can access this controller by running the following command from CLI.

```
php ./public/index.php image-optimiser --image='./public/images/test.png'
```

Service
-------

[](#service)

The service class allows you to apply this package virtually everywhere in your ZF3 application. We support logging and catch all output given from the programs doing the optimalisation.

The service by default gets decked out with a default `Zend\Log\Writer\Mock` writer. You can still access the logs in this writer. You can override this when building the service. Allowing you to provide a DB, Logfile or Stdout writer.

```
class SomeFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        /** @var ImageOptimiserService $imageOptimiserService */
        $imageOptimiserService = $container->get(ImageOptimiserService::class);

        # or... provide your own LoggerInterface

        /** @var Logger $logger */
        $logger = $container->get(Logger::class);
        /** @var Stream $writer */
        $logger->addWriter(new Stream('php://output'));
        /** @var ImageOptimiserService $imageOptimiserService */
        $imageOptimiserService = $container->build(ImageOptimiserService::class, ['logger' => $logger]);

        # ... other factory stuff
    }
}
```

If you want to access the logs in the Mock writer, just use the following snippet. Locate the Mock writer and then look at the events.

```
/** @var array|WriterInterface[] $writers */
$writers = $imageOptimiserService->getLogger()->getWriters()->toArray();
/** @var Zend\Log\Writer\Mock $mockWriter */
$mockWriter = $writers[0];
/** @var array $events */
$events = $mockWriter->events;
```

FAQs
----

[](#faqs)

There are none at the moment.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Total

4

Last Release

2402d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1207082?v=4)[Rob van der Lee](/maintainers/rvdlee)[@rvdlee](https://github.com/rvdlee)

---

Top Contributors

[![rvdlee](https://avatars.githubusercontent.com/u/1207082?v=4)](https://github.com/rvdlee "rvdlee (12 commits)")

---

Tags

image-optimizerzf3pngquantZend Framework 3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rvdlee-zf-image-optimiser/health.svg)

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

###  Alternatives

[spatie/image-optimizer

Easily optimize images using PHP

2.9k71.3M109](/packages/spatie-image-optimizer)[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)[typisttech/image-optimize-command

Easily optimize images using WP CLI

1722.0k](/packages/typisttech-image-optimize-command)[jkphl/iconizr

A PHP command line tool for converting SVG images to a set of CSS icons (SVG &amp; PNG, single icons and / or CSS sprites) with support for image optimization and Sass output

4869.0k](/packages/jkphl-iconizr)[joshembling/image-optimizer

Optimize your Filament images before they reach your database.

111145.4k12](/packages/joshembling-image-optimizer)[davidhavl/dherrorlogging

Full featured error logging module for ZF2/ZF3 application

1924.5k](/packages/davidhavl-dherrorlogging)

PHPackages © 2026

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