PHPackages                             lawondyss/imager - 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. lawondyss/imager

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

lawondyss/imager
================

The library for manage images and thumbnails. Library uses ImageMagick in command line.

1.6.2(9y ago)499MIT

Since Nov 11Compare

[ Source](https://github.com/Lawondyss/Imager)[ Packagist](https://packagist.org/packages/lawondyss/imager)[ RSS](/packages/lawondyss-imager/feed)WikiDiscussions Synced 2w ago

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

Imager
======

[](#imager)

Imager is manager for images and thumbnails.

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

[](#installation)

Installation performed by [Composer](https://getcomposer.org/). Write to command line `composer require lawondyss/imager`.

CAUTION
-------

[](#caution)

Library used [ImageMagick](http://www.imagemagick.org/) over command line. Is necessary have ImageMagick installed in system.

Generating image cannot be greater than 200 % of original image.

Examples
--------

[](#examples)

### Create thumbnails

[](#create-thumbnails)

```
// Image accepts argument of image as instance of class Imager\ImageInfo (extends SplFileInfo)
$imageInfo = new Imager\ImageInfo('path/to/image.jpg');
$image = new Imager\Image($imageInfo);

// create over factory
// ImageFactory::create() accepts image name in string or instance of ImageInfo
$factory = new Imager\ImageFactory;
$image = $factory->create('path/to/image.jpg');

/** Thumbnails **/
// resize by width
$thumb = $image->resize(100); // instance of Imager\ImageInfo with temporary image
var_dump($thumb->getPathname()); // path to thumbnail

// resize by height
$thumb = $image->resize(null, 100);

// resize with crop, cropped image is centered
$thumb = $image->resize(100, 100);

// origin dimensions
$thumb = $image->resize(0, 0);

/** Quality **/
// set in third parameter, lower is worse, 0 is default quality
$thumb = $image->resize(0, 0, 25);

/** Send image to output **/
header('Content-Type: ' . $thumb->getMime());
header('Content-Length: ' . $thumb->getSize());
echo $thumb->getContent();
```

### Repository for sources images and thumbnails

[](#repository-for-sources-images-and-thumbnails)

```
$factory = new Imager\ImageFactory;

// first argument is required; is directory with sources
// second argument is optional; is directory for thumbnails; if not set, then is same as directory for sources; autocreated
$repository = new Imager\Repository('path/to/sources', 'path/to/thumbnails');

// create ImageInfo of source image
$uploadImageInfo = $factory->createInfo('path/to/uploaded/image.jpg');

// source image has not source, therefore save to sources directory
// second optional argument defined new name for saved image
$sourceImageInfo = $repository->save($uploadImageInfo, 'image.jpg'); // instance of Imager\ImageInfo with saved source image

// fetch source image only by name
$imageInfo = $repository->fetch('image.jpg'); // instance of Imager\ImageInfo with source image

// created thumbnail
$thumb = $factory->create($imageInfo)->resize(100); // instance of Imager\ImageInfo with temporary thumbnail of image

// thumbnail has source, therefore save to thumbnails directory
$thumbImageInfo = $repository->save($thumb); // instance of Imager\ImageInfo with saved thumbnail
```

Nette extension
---------------

[](#nette-extension)

For registration Imager as Nette extension is required add this configuration.

```
extensions:
    imager: Imager\DI\Extension
```

Extension has this configuration:

```
imager:
    sourcesDir: %appDir%/../cdn/assets # required
    thumbsDir: %wwwDir%/images/thumbs
    baseUrl: http://cdn.example.com # if is your images in another URL
    basePath: images/thumbs/ # required; adds this path to URL
    errorImage: on # default on; displays error image if when generating an error occurred
    debugger: on # default as debugMode; display information in debug bar; WARNING! For every image send new HEAD request!
```

Example with extension
----------------------

[](#example-with-extension)

Presenter for upload and show images

```
class ImagerPresenter extends BasePresenter
{
    /** @var \Imager\Repository @inject */
    public $repository;

    /** @var \Imager\ImageFactory @inject */
    public $factory;

    public function renderDefault($id)
    {
        if (isset($id)) {
            $this->template->imageFromString = $id;
            $this->template->imageFromRepository = $this->repository->fetch($id);
        }
    }

    protected function createComponentUploadForm()
    {
        $control = new Nette\Application\UI\Form;

        $control->addUpload('photo')
            ->setRequired();
        $control->addSubmit('load', 'load image');
        $control->onSuccess[] = $this->uploadFormSucceed;

        return $control;
    }

    public function uploadFormSucceed(Nette\Application\UI\Form $form, $values)
    {
        $upload = $this->factory->createInfo($values->photo->getTemporaryFile());
        $source = $this->repository->save($upload);

        $this->redirect('default', $source->getFilename());
    }
}
```

Latte template

```
{block content}
{control uploadForm}
{ifset $image}
     {* set width, origin height *}
     {* set width and height *}
     {* resize by height *}
     {* resize by width *}
     {* origin width and height *}

    {* set quality *}
     {* origin width and height, but lowest quality *}

    {* same parameters as for $imageFromRepository *}

{/ifset}

```

### Link to image

[](#link-to-image)

If you required create link to image (example to e-mail), then is here method `ImageFactory::createLink()`. Create a link is only possible when integrating into the Nette.

```
class EmailPresenter extends BasePresenter
{
    /** @var \Imager\ImageFactory @inject */
    public $factory;

    public function actionSendEmail($email)
    {
        // ... defines $images as array with Imager\ImageInfo objects or names of images

        $linksHtml = [];
        foreach ($images as $image) {
          $linksHtml = $this->createImg($this, $image);
        }

        // ... functionality for send e-mail
    }

    private function createImg($image, $width = null, $height = null)
    {
        $link = $this->factory->createLink($this, $image, $width, $height);

        $img = Nette\Utils\Html::el('img', ['src' => $link]);

        return $img->render();
    }
}
```

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity69

Established project with proven stability

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

Recently: every ~82 days

Total

9

Last Release

3589d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f642f8a219fdaad6b73c302bfc3a623148b8eefd58ea4078cdfae1f24c47fc5?d=identicon)[Lawondyss](/maintainers/Lawondyss)

### Embed Badge

![Health badge](/badges/lawondyss-imager/health.svg)

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

###  Alternatives

[nette/security

🔑 Nette Security: provides authentication, authorization and a role-based access control management via ACL (Access Control List)

3899.8M346](/packages/nette-security)[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

54110.3M291](/packages/nette-mail)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5266.1M136](/packages/symplify-monorepo-builder)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2613.3M487](/packages/ssch-typo3-rector)[nette/component-model

⚛ Nette Component Model

28817.1M114](/packages/nette-component-model)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136411.0k14](/packages/rector-rector-src)

PHPackages © 2026

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