PHPackages                             harmim/images - 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. harmim/images

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

harmim/images
=============

A tool for working with images.

v3.1.0(2y ago)2457MITPHPPHP &gt;=8.2

Since Jun 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/harmim/images)[ Packagist](https://packagist.org/packages/harmim/images)[ Docs](https://github.com/harmim/images)[ RSS](/packages/harmim-images/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (9)Versions (12)Used By (0)

A tool for working with images
==============================

[](#a-tool-for-working-with-images)

[![Build](https://github.com/harmim/images/actions/workflows/build.yml/badge.svg)](https://github.com/harmim/images/actions/workflows/build.yml)[![Coding Style](https://github.com/harmim/images/actions/workflows/coding-style.yml/badge.svg)](https://github.com/harmim/images/actions/workflows/coding-style.yml)[![Static Analysis](https://github.com/harmim/images/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/harmim/images/actions/workflows/static-analysis.yml)[![Tests](https://github.com/harmim/images/actions/workflows/tests.yml/badge.svg)](https://github.com/harmim/images/actions/workflows/tests.yml)[![Coverage](https://camo.githubusercontent.com/14e7ab3d12180e2460926cadb3d5b35ce638fb00b3d2add837a708a107ef956c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6861726d696d2f696d616765732f62616467652e737667)](https://coveralls.io/github/harmim/images)[![Monthly Downloads](https://camo.githubusercontent.com/086a661c7349379a595b8bede0f241ad5b0dc6595124ff3b30e104dee1ad98d0/68747470733a2f2f706f7365722e707567782e6f72672f6861726d696d2f696d616765732f642f6d6f6e74686c79)](https://packagist.org/packages/harmim/images)[![Total Downloads](https://camo.githubusercontent.com/1b92a55b51d24315f46f3fd830f2987439e2d4a5913ff2d8568d196cb255135a/68747470733a2f2f706f7365722e707567782e6f72672f6861726d696d2f696d616765732f646f776e6c6f616473)](https://packagist.org/packages/harmim/images)[![Version](https://camo.githubusercontent.com/5ac04e7c2557b6ed7d17b740e7265998a88039ed5cf32be93abdd91bd01018fb/687474703a2f2f706f7365722e707567782e6f72672f6861726d696d2f696d616765732f76657273696f6e)](https://github.com/harmim/images/tags)[![PHP Version Require](https://camo.githubusercontent.com/1da57e866b5e6156b571dcf724efc6b5b44466450da0d707dd4a597bb3f80ebf/687474703a2f2f706f7365722e707567782e6f72672f6861726d696d2f696d616765732f726571756972652f706870)](https://packagist.org/packages/harmim/images)[![License](https://camo.githubusercontent.com/4ce92a0b40275987419995c069d67a4982df308832fecd2322b016b72a39cbb5/68747470733a2f2f706f7365722e707567782e6f72672f6861726d696d2f696d616765732f6c6963656e7365)](https://github.com/harmim/images/blob/master/LICENSE.md)

About
-----

[](#about)

A tool for working with images. It can be used as an extension of the [Nette Framework](https://nette.org).

There is `Image storage` for storing images easily and/or deleting them from the storage. There are also several ways how to resize and/or process images. Then, you can get a stored image path directly, or you can use prepared [Latte](https://latte.nette.org) macros to generate HTML tags. See [Usage](#Usage).

**Requires the PHP version `8.2` or newer and PHP extensions `fileinfo`, `gd`, and `intl`.**

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

[](#installation)

Download the [latest release](https://github.com/harmim/images/tags) or use Composer:

```
composer require harmim/images
```

Usage
-----

[](#usage)

For working with images, we need `\Harmim\Images\ImageStorage`:

### Without Nette

[](#without-nette)

```
$customConfig = [
	'wwwDir' => __DIR__ . DIRECTORY_SEPARATOR . 'www',
	'compression' => 90,
	'placeholder' => 'images/foo.png',
	'types' => [
		'img-small' => [
			'width' => 50,
			'height' => 50,
			'transform' => \Harmim\Images\Resize::Exact,
			...
		],
		...
	],
	...
];
$imageStorage = $customConfig + \Harmim\Images\Config\Config::Defaults;
```

In `$customConfig`, you can specify a custom configuration. See [Configuration](#Configuration).

### With Nette

[](#with-nette)

You can enable and customise the extension using your NEON config:

```
extensions:
  images: \Harmim\Images\DI\ImagesExtension

images:
  compression: 90
  placeholder: images/foo.png
  types:
    img-small:
      width: 50
      height: 50
      transform: ::constant(\Harmim\Images\Resize::Exact)
      ...
    ...
  ...
```

In the `images` section, you can specify a custom configuration. See [Configuration](#Configuration).

`\Harmim\Images\ImageStorage` is now registrated in the DI container. You can get it directly from the container:

```
/** @var \Nette\DI\Container $container */
$imageStorage = $container->getService('images.imageStorage');
// or
$imageStorage = $container->getByType(\Harmim\Images\ImageStorage::class);
```

Of course, you can inject `\Harmim\Images\ImageStorage` through a constructor, inject method, inject annotation, or any other way.

If you want to use `\Harmim\Images\ImageStorage` in a presenter or control where inject methods are called, you can use trait `\Harmim\Images\TImageStorage`. In your presenters, controls, and theire templates, there will be variable `$imageStorage`.

```
abstract class BasePresenter extends \Nette\Application\UI\Presenter
{
	use \Harmim\Images\TImageStorage;
}

abstract class BaseControl extends \Nette\Application\UI\Control
{
	use \Harmim\Images\TImageStorage;
}
```

The extension installs images macros to Latte. See [Macros](#Macros).

### Storing Images

[](#storing-images)

You can store an image using method `\Harmim\Images\ImageStorage::saveImage(string $name, string $path): string` or `\Harmim\Images\ImageStorage::saveUpload(\Nette\Http\FileUpload $file): string`. An original image will be stored; then, it will be compresed.

Both methods return a stored image file name. You can use this file name to delete, resize, or retrieve the image.

Images are stored with a unique file name and location.

### Deleting Images

[](#deleting-images)

Using method `\Harmim\Images\ImageStorage::deleteImage(string $fileName, array $excludedTypes = []): void`, you can delete an image by `$fileName` which should be a file name returned by `\Harmim\Images\ImageStorage::saveImage` or `\Harmim\Images\ImageStorage::saveUpload`.

If you pass `$excludedTypes`, only other types will be deleted; otherwise, all types, the original image, and the compressed image will be deleted.

### Getting Stored Images' Paths

[](#getting-stored-images-paths)

You can get a stored image path using method `\Harmim\Images\ImageStorage::getImageLink(string $fileName, ?string $type = null, array $options = []): ?string`or [Macros](#Macros). You can pass a specific type defined in an inital configuration, or you can pass specific options. See [Configuration](#Configuration). `$fileName` should be a file name returned by `\Harmim\Images\ImageStorage::saveImage` or `\Harmim\Images\ImageStorage::saveUpload`.

If you try to get an image of a size or a type for a first time, this image is not yet created, so it will be created now. Next time, you will get a resized image.

If the image does not exist, a placeholder will be returned.

In case you need to get an original/compressed image, in the configuration, you can use `orig/compressed`, respectively. For example, `['orig' => true]`. It is also possible to use these options in macros.

### Macros

[](#macros)

#### `img`

[](#img)

```
{img [$image] [image-type] [options]}
```

Renders the `img` tag:

```

```

or tags for lazy loading with the `lazy` option:

```

```

Examples:

```
{img alt => 'foo'} {* returns a path to a placeholder *}

{* '$image' is a file name *}
{img $image alt => 'foo'}
{img $image width => 200, height => 200, alt => 'foo'}

{* 'img-small' is an image type defined in the configuration *}
{img $image img-small alt => 'foo'}
{img $image img-small compression => 90, alt => 'foo', class => 'bar'}

{img $image img-small lazy => true, alt => 'foo'}
{img $image img-small lazy => true, width => 500, height => 650, alt => 'foo'}
```

#### `n:img`

[](#nimg)

```

```

Renders the `src` attribute. It can be used, e.g., in the `img` element.

Examples:

```
 {* renders a path to a placeholder *}

{* '$image' is a file name *}

{* 'img-small' is an image type defined in the configuration *}

```

#### `imgLink`

[](#imglink)

```
{imgLink [$image] [image-type] [options]}
```

Returns a relative path (from the resource root directory) to a given image.

Examples:

```
{imgLink} {* returns a path to a placeholder *}

{* '$image' is a file name *}
{imgLink $image}
{imgLink $image width => 200, height => 200}

{* 'img-small' is an image type defined in the configuration *}
{imgLink $image img-small}
{imgLink $image img-small compression => 90}

```

Configuration
-------------

[](#configuration)

- `wwwDir`: (`string`) An absolute path to the resource root directory.
    - Default: `%wwwDir%` in Nette; otherwise, you have to specify this parameter.
- `imagesDir`: (`string`) A relative path (from `wwwDir`) to a directory for storing images.
    - Default: `data/images`.
- `origDir`: (`string`) A relative path (from `imagesDir`) to a directory for storing original images.
    - Default: `orig`.
- `compressionDir`: (`string`) A relative path (from `imagesDir`) to a directory for storing compressed images.
    - Default: `imgs`.
- `placeholder`: (`string`) A relative path (from `wwwDir`) to an image placeholder (when an image is not found).
    - Default: `img/noimg.jpg`.
- `width`: (`int`) An image width.
    - Default: `1024`.
- `height`: (`int`) An image height.
    - Default: `1024`.
- `compression`: (`int`) A compression quality. See `\Nette\Utils\Image::save`.
    - Default: `85`.
- `transform`: (`\Harmim\Images\Resize|list`) See [Transform-Options](#Transform-Options).
    - Default: `\Harmim\Images\Resize::OrSmaller`.
- `allowedImgTagAttrs`: (`list`) `img` attributes you can use in the `{img}` Latte macro, other attributes are ignored.
    - Default: `[alt, height, width, class, hidden, id, style, title, data]`.
- `lazy`: (`bool`) Render the `{img}` Latte macro as a lazy image (with the `data-src` attribute, `lazy` class, and normal `img` tag in the `noscript`tag).
    - Default: `false`.
- `types`: (`array`) A configuration for image types overriding the default configuration.
    - Default: `[]`.
    - Example:

```
types:
  img-small:
    width: 50
    height: 50
  img-gallery:
    lazy: true
    transform:
    	- ::constant(\Harmim\Images\Resize::Stretch)
    	- ::constant(\Harmim\Images\Resize::Cover)
```

- `destDir`: (`?string`) A directory where to find images.
    - Default: `null`.
- `orig`: (`?bool`) When set to `true`, the original image will be returned.
    - Default: `null`.
- `compressed`: (`?bool`) When set to `true`, the original compressed image will be returned.
    - Default: `null`.

### Transform-Options

[](#transform-options)

OptionDescription`\Harmim\Images\Resize::ShrinkOnly`Only shrinking (prevents a small image from being stretched).`\Harmim\Images\Resize::Stretch`Do not keep the aspect ratio.`\Harmim\Images\Resize::OrSmaller`The resulting dimensions will be smaller or equal to the required dimensions.`\Harmim\Images\Resize::OrBigger`Fills (and possibly exceeds in one dimension) the target area.`\Harmim\Images\Resize::Cover`Fills the target area and cuts off what goes beyond.`\Harmim\Images\Resize::Exact`Placees a not stretched image to the exact blank area.License
-------

[](#license)

This tool is licensed under the [MIT license](https://github.com/harmim/images/blob/master/LICENSE.md).

---

Author: **Dominik Harmim &lt;&gt;**

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

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

Recently: every ~544 days

Total

11

Last Release

1091d ago

Major Versions

v1.1.3 → v2.0.02017-09-10

v2.0.1 → v3.0.02023-06-30

PHP version history (2 changes)v1.0.0PHP &gt;= 7.1

v3.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a9904127e8d05c1dcc6a8be835993bdbeb75641fffa40b78ec1132d8dbe8f35?d=identicon)[harmim](/maintainers/harmim)

---

Top Contributors

[![harmim](https://avatars.githubusercontent.com/u/13155661?v=4)](https://github.com/harmim "harmim (29 commits)")

---

Tags

extensiongdimagesnette-frameworkphpphpnettegdimages

### Embed Badge

![Health badge](/badges/harmim-images/health.svg)

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

###  Alternatives

[contributte/translation

Symfony/Translation integration for Nette Framework.

771.8M50](/packages/contributte-translation)[brabijan/images

Image storage for Nette Framework

5617.7k](/packages/brabijan-images)[pavlista/nette-palette

Palette support for Nette Framework and Latte template engine

1658.6k](/packages/pavlista-nette-palette)[dotblue/nette-webimages

On-the-fly generated web images for your Nette app

262.1k](/packages/dotblue-nette-webimages)[kollarovic/thumbnail

Generating image thumbnails

1036.1k2](/packages/kollarovic-thumbnail)[duxweb/dux-lite

The lightweight framework based on slim php

161.0k9](/packages/duxweb-dux-lite)

PHPackages © 2026

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