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

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

rvdlee/zf-image-resizer
=======================

A package that allows you resize images with programs like ImageMagick.

0.0.3(5y ago)01551[3 issues](https://github.com/rvdlee/zf-image-resizer/issues)MITPHPPHP ^7.2 || ^7.3

Since Nov 10Pushed 5y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (8)Versions (5)Used By (0)

ZF3 Package to resize images
============================

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/8286392617e3005191634a449579cd723927172fc3623b89eac57aa713a2cbe2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7276646c65652f7a662d696d6167652d726573697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rvdlee/zf-image-resizer)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a3d5c8955b73158cdd538d5ec61f7145bae4b6894543146eb298770e5c013ce6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7276646c65652f7a662d696d6167652d726573697a65722f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/rvdlee/zf-image-resizer)[![Total Downloads](https://camo.githubusercontent.com/427bc24fc33634eda33804b83918d678a46e0404abdd621473ab67faec3e094c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7276646c65652f7a662d696d6167652d726573697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rvdlee/zf-image-resizer)[![GitHub license](https://camo.githubusercontent.com/7f9326402725db0a4af85c0bfa8cdb44fc45015c4da62e87b0e09d72f8740d6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7276646c65652f7a662d696d6167652d726573697a65722e737667)](https://github.com/rvdlee/zf-image-resizer/blob/master/LICENSE)[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.me/epicsoftworks)

This is a image resizer package. I've written this with ZF3 in mind, everything is written with configuration over convention in mind. Highly extendible and easy in use. You can use this along side my other package to optimise images.

Key features of this package is:

- Resizing through InputFilters
- Resizing through the Service object
- Resizing on the fly

Usage
=====

[](#usage)

To get started you need to choose one of the programs to resize with. By default we support [ImageMagick ](https://imagemagick.org/index.php) out of the box. It is mainstream and does a fantastic job at resizing images while maintaining great image quality.

You will need a bit of configuration to get started. We kept the validation chain simple since ImageMagick support over 200 formats. If you are writing your own adapter you now have the option to validate if the image is suitable for resizing through that adapter.

```
# ... config use statements

return [
    'rvdlee' => [
        'zf-image-resizer'   => [
            'adapter'         => ImageMagick::class,
            'validator-chain' => [
                ['name' => IsImage::class],
            ],
        ],
    ],
];
```

The model has a few calculations build in and some fallback logic when certain parameters are not provided. A good example would be the ratio scaling when only the width or height is provided.

Other calculations included is to crop based on one of nine locations on the image. Here are a few examples of crops. The [beautiful image](https://unsplash.com/photos/CQl3Y5bV6FA) was published under a free license by [Scott Walsh](https://unsplash.com/@outsighted). Thanks for doing that!

Here we have the full image. I resized the original photo for the example because its quality and resolution was a bit high to illustrate an image resizer.

[![Full image, by ](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/full.jpg)](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/full.jpg)

Let's start simple. An image resize. You can resize the following image using one of the two methods, you can define the width and height `$imageResizerService->resizeImage($file->getPath(), 300, 200)` or simply only provide the width `$imageResizerService->resizeImage($file->getPath(), 300)` or height `$imageResizerService->resizeImage($file->getPath(), 0, 200)`. When you only provide either of them, it will rescale the image by ratio.

[![Resized to 300x200](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/resized.jpg)](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/resized.jpg)

Then there is a simple crop. We are going to use build-in calculations to crop the center of the image with a defined cropped width and height. `$imageResizerService->cropImage($file->getPath(), 350, 350, Image::CENTERED_CROP)))`.

[![Cropped 350x350 Centered](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/centered_crop.jpg)](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/centered_crop.jpg)

You are the master of your own crop and you can define the width and height how you want. Choosing the centered or any other mode already provided by the package. `$imageResizerService->cropImage($file->getPath(), 300, 450, Image::CENTERED_CROP)`

[![Cropped 300x450 Centered](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/freeform_crop.jpg)](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/freeform_crop.jpg)

Additionally, there is also an manual mode if you want full control. The last two parameters are the `x` and `y` coordinates of the crop.`$imageResizerService->cropImage($file->getPath(), 400, 400, Image::MANUAL_CROP, 0, 400)`

[![Manual 400x400 crop with own coordinates](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/manual_crop.jpg)](https://github.com/rvdlee/zf-image-resizer/raw/master/examples/manual_crop.jpg)

InputFilters
============

[](#inputfilters)

Just like my [optimiser package](https://github.com/rvdlee/zf-image-optimiser) we support InputFilters to make resizing a breeze when uploading photo's like avatars for example. Passing along the `Image::CENTERED_CROP` option to the service object automatically makes a centered crop of the original video.

Using an InputFilter is easy.

```
$this->add(
    [
        'type'       => FileInput::class,
        'name'       => 'avatar',
        'required'   => false,
        'filters'    => [
           	# ... Other filters
            [
                'name'    => ImageResizer::class,
                'options' => [
                    'mode'        => Image::ONLY_CROP_MODUS,
                    'crop_mode'   => Image::CENTERED_CROP,
                    'crop_width'  => 100,
                    'crop_height' => 100,
                ],
            ],
        ],
        'validators' => [
            # ... Validators
        ],
    ]
);
```

Service
=======

[](#service)

The service object is the baseline of the resizer. You can use DI to instance this anywhere in your zend application. We also use support logging to catch all output from the programs used to resize images.

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 ImageResizerService $imageOptimiserService */
        $imageResizerService = $container->get(ImageResizerService::class);

        # or... provide your own LoggerInterface

        /** @var Logger $logger */
        $logger = $container->get(Logger::class);
        /** @var Stream $writer */
        $logger->addWriter(new Stream('php://output'));
        /** @var ImageResizerService $imageOptimiserService */
        $imageResizerService = $container->build(ImageResizerService::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 = $imageResizerService->getLogger()->getWriters()->toArray();
/** @var Zend\Log\Writer\Mock $mockWriter */
$mockWriter = $writers[0];
/** @var array $events */
$events = $mockWriter->events;
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

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

Total

3

Last Release

2055d 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 (19 commits)")

---

Tags

ImageMagickzf3Zend Framework 3image resizer

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/glide

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

2.6k51.2M116](/packages/league-glide)[james-heinrich/phpthumb

The PHP thumbnail generator

318516.1k6](/packages/james-heinrich-phpthumb)[davidhavl/dherrorlogging

Full featured error logging module for ZF2/ZF3 application

1924.5k](/packages/davidhavl-dherrorlogging)[orbitale/imagemagick-php

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

43385.7k1](/packages/orbitale-imagemagick-php)[admad/cakephp-glide

CakePHP plugin for using Glide image manipulation library.

34160.7k1](/packages/admad-cakephp-glide)[hrevert/ht-img-module

Image manipulation module for Zend Framework 2

1829.6k2](/packages/hrevert-ht-img-module)

PHPackages © 2026

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