Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ed3638c
Fix lazy Twig mode dropping the path for absolute image URLs
Jul 11, 2026
2b43fd9
Explain and test the host guard in cleanPath()
Jul 29, 2026
6369aca
Merge pull request #1655 from Atesca/bugfix-1447-lazy-absolute-url
dbu Aug 5, 2026
0f4a5f7
fix codestyle
Aug 5, 2026
7365bb8
Merge pull request #1657 from liip/cs-fix
dbu Aug 5, 2026
548846e
prepare release
Aug 5, 2026
f5cdefb
drop support for PHP 8.0, the build was not installable anymore anyways
Aug 5, 2026
346274b
Merge pull request #1658 from liip/drop-php-8.0
dbu Aug 5, 2026
ee66cb6
Clear WebP cache variant on CacheManager::remove()
ousamabenyounes Aug 10, 2026
8738393
Merge pull request #1661 from ousamabenyounes/bugfix-1504-clear-webp-…
dbu Aug 14, 2026
c985db8
update changelog
dbu Aug 14, 2026
671ffdf
Add native return type to RelativeResize::apply()
ousamabenyounes Aug 10, 2026
63cad5b
Remove redundant return type test
ousamabenyounes Aug 18, 2026
3b62ee9
Merge pull request #1660 from ousamabenyounes/bugfix-1618-relativeres…
dbu Aug 20, 2026
6f3e417
Dispatch events on the cache storage lifecycle
ousamabenyounes Aug 21, 2026
d5e564e
Merge pull request #1664 from ousamabenyounes/feature-1280-cache-life…
dbu Sep 6, 2026
0aa0040
Fall back to the default image when an image cannot be generated (#1665)
Amoifr Sep 6, 2026
76dbda1
The transparency of the background filter is an alpha, not a transpar…
Amoifr Sep 10, 2026
d43fa18
Merge pull request #1667 from Amoifr/fix-1654-transparency-doc
dbu Sep 11, 2026
b1de562
Merge pull request #1668 from Amoifr/docs-1608-asset-mapper-versioning
Amoifr Oct 2, 2026
799fcfc
Dispatch filter lifecycle events (#1666)
ousamabenyounes Oct 2, 2026
6558c17
prepare release
dbu Oct 2, 2026
2288e30
Return a not found response for a non-existing filter outside of the …
Amoifr Oct 6, 2026
b6a29cb
Merge pull request #1669 from Amoifr/bugfix-non-existing-filter-defau…
dbu Oct 7, 2026
3c799cf
prepare release
dbu Oct 7, 2026
623215d
Apply quality to all Vips image formats
ousamabenyounes Aug 23, 2026
9130a3d
Add missing return type for Twig 4 compatibility
winniezzz Oct 23, 2026
33bc6ce
Merge pull request #1662 from ousamabenyounes/bugfix-1601-vips-quality
dbu Nov 8, 2026
3a1bdc3
add changelog
dbu Nov 8, 2026
7a90413
Merge branch '2.x' into twig-4-support
dbu Nov 8, 2026
023c094
Merge pull request #1673 from winniezzz/twig-4-support
dbu Nov 8, 2026
46b2d0a
Add a format_extension resolver configuration
Amoifr Nov 8, 2026
0f23894
Link the pull request in the changelog
Amoifr Nov 8, 2026
abcf5a8
Merge pull request #1675 from Amoifr/feature-1619-format-extension-re…
dbu Nov 14, 2026
6e02f92
Add the normalize_filter_set_names option and deprecate the normaliza…
Amoifr Nov 15, 2026
b01784e
pin cs-fixer version
dbu Nov 15, 2026
01f5d62
Merge pull request #1677 from liip/fix-cs-fixer
dbu Nov 15, 2026
f165a4c
Merge branch '2.x' into 2-to-upgrade-branch
dbu Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
php-version: 8.3
coverage: none
tools: php-cs-fixer
tools: php-cs-fixer:3.95.30

- name: Run PHP-CS-Fixer
run: php-cs-fixer fix --dry-run --diff
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ for a given releases. Unreleased, upcoming changes will be updated here periodic

# 2.x

## 2.19.0 (unreleased)

- Add a `format_extension` resolver configuration, so the `FormatExtensionResolver` can decorate a configured resolver without declaring a service ([Amoifr](https://github.com/liip/LiipImagineBundle/pull/1675))
- Add the `normalize_filter_set_names` option to allow `-` in filter set names, and deprecate the normalization of `-` to `_` ([Amoifr](https://github.com/liip/LiipImagineBundle/pull/1676))

## [2.18.2](https://github.com/liip/LiipImagineBundle/tree/2.18.2)

- Make compatible with Twig 4: Add missing return type declaration ([winniezzz](https://github.com/liip/LiipImagineBundle/pull/1673))
- Fix quality fallback with rokka/imagine-vips ([ousamabenyounes](https://github.com/liip/LiipImagineBundle/pull/1662))

## [2.18.1](https://github.com/liip/LiipImagineBundle/tree/2.18.1)

- Fix a non-existing filter throwing an uncaught exception instead of a not found response outside of the debug mode, a regression of the default image fallback ([Amoifr](https://github.com/liip/LiipImagineBundle/pull/1665))

## [2.18.0](https://github.com/liip/LiipImagineBundle/tree/2.18.0)

- Dispatch filter lifecycle events for telemetry and debugging ([ousamabenyounes](https://github.com/liip/LiipImagineBundle/pull/1666))
- Fall back to the `default_image` when a filter does not exist or the image can not be generated, unless the new `controller.debug` option is enabled ([Amoifr](https://github.com/liip/LiipImagineBundle/pull/1665))
- Dispatch pre/post store and pre/post remove events on the CacheManager, so applications can react to the cache storage lifecycle ([ousamabenyounes](https://github.com/liip/LiipImagineBundle/pull/1664))
- Fix bug that we did not delete the webp variant when enabled, when deleting an image through the CacheManager ([ousamabenyounes](https://github.com/liip/LiipImagineBundle/pull/1661))
- Drop support for PHP 8.0.

## [2.17.2](https://github.com/liip/LiipImagineBundle/tree/2.17.2)

- Fix lazy Twig mode dropping the path for absolute image URLs ([Atesca](https://github.com/Atesca))
Fixing a regression introduced in 2.7.0.

## [2.17.1](https://github.com/liip/LiipImagineBundle/tree/2.17.1)

- Fix for AssetMapperLoaderFactory service definition to not fail when not configured ([dbu](https://github.com/liip/LiipImagineBundle/pull/1649))
Expand Down
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ been removed.

- __[BC BREAK]__ Argument 2 of `AbstractDoctrineLoader` is mandatory now, you MUST pass the model class name.

## 2.19.0

- __[Deprecated]__ A filter set name that contains a `-` and no `_` is renamed by the Symfony configuration, so
`my-thumbnail` has to be used as `my_thumbnail`. This normalization is deprecated and will be removed in 3.0. Set the
new `liip_imagine.normalize_filter_set_names` option to `false` to use the filter set names as written, and make sure
the names in your configuration match the names used in your templates and code literally.

## 2.3.0 - 2.7.0

- __[Deprecated]__ As `doctrine/cache` has been deprecated, the `Liip\ImagineBundle\Imagine\Resolver\CacheResolver`
Expand Down
21 changes: 21 additions & 0 deletions doc/asset-versioning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ setting for ``framework.assets.json_manifest_path``. The manifest file is used
to lookup the location of the actual file, and append the versioning string to
the resulting image URL so that cache busting is used.

Asset Mapper
~~~~~~~~~~~~

Symfony's `AssetMapper`_ puts the version in the file name rather than in a
query string or in a manifest, so neither of the two integrations above applies
to it.

In production there is nothing to configure: ``asset-map:compile`` writes the
versioned files into the public directory, where the ``filesystem`` data loader
finds them like any other file.

In development the versioned files do not exist on disk, because AssetMapper
serves the assets from their source directory, so the ``filesystem`` loader
answers that the source image could not be found. Use the
:doc:`asset mapper data loader <data-loader/asset_mapper>`, which maps the
versioned public path back to its source file.

Images that are not AssetMapper assets, such as uploads, are not versioned and
keep being loaded by the ``filesystem`` loader from wherever they are stored.

Cache Busting
~~~~~~~~~~~~~

Expand Down Expand Up @@ -59,3 +79,4 @@ configured Symfony to append an asset version, you now won't be able to use the
``asset`` Twig function with the ``imagine_filter``.

.. _`asset version`: https://symfony.com/doc/current/reference/configuration/framework.html#reference-framework-assets-version
.. _`AssetMapper`: https://symfony.com/doc/current/frontend/asset_mapper.html
18 changes: 18 additions & 0 deletions doc/basic-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ can configure the generation of all images in the WebP format.
default_filter_set_settings:
format: webp

The images are then encoded in WebP, but are still cached under the extension of the
source image (``cats.jpeg``), so a web server serving them directly may send them with
the wrong content type. To also give them the ``.webp`` extension, use the
:ref:`format extension resolver <cache-resolver-format-extension>`:

.. code-block:: yaml

# app/config/config.yml

liip_imagine:
resolvers:
format_extension:
format_extension:
resolver: default
cache: format_extension
default_filter_set_settings:
format: webp

Use WebP if supported
~~~~~~~~~~~~~~~~~~~~~

Expand Down
63 changes: 47 additions & 16 deletions doc/cache-resolver/format_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,28 @@ FormatExtensionResolver
The ``FormatExtensionResolver`` cannot be used by itself. Instead, it is a "decorator" for
another resolver. It adds the ability to set the correct file extension when a filter converted the image format.

For example, with a filter set using ``format: webp``, the source image ``image.png`` is
stored and served as ``image.webp`` instead of a WebP image named ``image.png``.

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

To use this cache resolver, you must first define the cache resolver it will decorate.
In this example, we will use the :ref:`Web Path Resolver <cache-resolver-web-path>`.

Next, we need to define a service for this cache resolver and inject the web path cache resolver service to decorate.
Define a resolver with the ``format_extension`` key, and give it the name of the configured
resolver to decorate. In this example, it decorates the ``default`` resolver, which is the
:ref:`Web Path Resolver <cache-resolver-web-path>` unless you configured another one:

.. code-block:: yaml

# app/config/services.yml

services:
acme.imagine.cache.format_extension:
class: Liip\ImagineBundle\Imagine\Cache\Resolver\FormatExtensionResolver
arguments:
- "@acme.imagine.cache.resolver.web_path"
- "@liip_imagine.filter.configuration"
tags:
- { name: "liip_imagine.cache.resolver", resolver: "format_extension" }
# app/config/config.yml

liip_imagine:
resolvers:
format_extension:
format_extension:
resolver: default

With this configuration, the format extension resolver will rewrite the extension to match the filter format.
For example, you have the source image ``image.png`` and you apply filter with format ``jpg`` you will get jpeg-image ``image.jpg``.
The decorated resolver must be defined in the ``resolvers`` section. The ``default``
resolver is always available, as the bundle defines it when it is not configured.

Usage
-----
Expand Down Expand Up @@ -61,5 +59,38 @@ filter set using the following configuration.
cache: ~
my_thumb:
cache: format_extension
format: webp
filters:
# the filter list

.. caution::

Changing the cache resolver changes the paths of the cached images. Images already
stored under their original extension are not found anymore and are generated again.

.. caution::

Do not combine this resolver with the ``webp.generate`` option on filter sets that
define a ``format`` other than ``webp``: with ``format: jpeg``, the WebP variant
``image.png.webp`` would be stored as ``image.png.jpeg``, a WebP image with the
extension of the format.

Usage with a Custom Service
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Before the ``format_extension`` resolver configuration was available, the resolver had to be
defined as a service. This still works, for example to decorate a resolver that is defined as
a service instead of in the ``resolvers`` section:

.. code-block:: yaml

# app/config/services.yml

services:
acme.imagine.cache.format_extension:
class: Liip\ImagineBundle\Imagine\Cache\Resolver\FormatExtensionResolver
arguments:
- "@acme.imagine.cache.resolver.custom"
- "@liip_imagine.filter.configuration"
tags:
- { name: "liip_imagine.cache.resolver", resolver: "format_extension" }
69 changes: 69 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ The default configuration for the bundle looks like this:
filter_action: liip_imagine.controller::filterAction
filter_runtime_action: liip_imagine.controller::filterRuntimeAction
redirect_response_code: 302
debug: ~ # %kernel.debug%
webp:
generate: false
quality: 100
cache: ~
data_loader: ~
post_processors: []
normalize_filter_set_names: ~ # true, deprecated
filter_sets:

# Prototype
Expand Down Expand Up @@ -79,6 +81,8 @@ There are several configuration options available:
* ``data_loader`` - name of a custom data loader. Default value: ``filesystem``
(which means the standard filesystem loader is used). Built-in loaders include:
``filesystem``, ``chain``, ``flysystem``, ``stream``, and ``asset_mapper``.
* ``default_image`` - image served when the requested one can not be delivered, for every filter set
that does not define its own. Default value: ``null``. See `Default image`_ below.
* ``twig.mode`` - Twig filter integration. ``none`` disables the twig filters, ``lazy`` enables
Twig using the Twig runtime for lazy loading. The default value is ``lazy``.
The twig filter automatically picks up the ``framework.assets.version`` configuration. You can
Expand All @@ -92,6 +96,8 @@ There are several configuration options available:
* ``redirect_response_code`` - The HTTP redirect response code to return from the imagine controller,
one of ``201``, ``301``, ``302``, ``303``, ``307``, or ``308``. Default value: ``302``
See :doc:`optimizations/avoid-redirects` if you want to change this configuration.
* ``debug`` - Whether an image that can not be generated is reported as an error. Default value:
``%kernel.debug%``. See `Default image`_ below.
* ``webp``
* ``generate`` - enabling the generation a copy of the image in the WebP format.
* ``quality`` - override the quality from filter option.
Expand All @@ -105,10 +111,16 @@ There are several configuration options available:
* ``driver`` - one of the drivers: ``gd``, ``imagick``, ``gmagick``, ``vips``.
Default value: ``gd``
* If you want to use vips, you need to additionally require ``rokka/imagine-vips``
* With vips, ``quality`` is applied to each output format's quality option.
* ``default_filter_set_settings`` - specify the default values that will be inherit for any set defined in
``filter_sets``. These values will be overridden if they are specified in the each set. In case of ``filters`` and
``post_processors``, the specified values will be merged with the default ones.
* ``filter_sets`` - specify the filter sets that you want to define and use.
* ``normalize_filter_set_names`` - whether ``-`` is replaced by ``_`` in the filter set names,
following the Symfony convention for configuration keys. Default value: ``true``. When this
normalization renames one of your filter sets, a deprecation is triggered unless you set the
option to ``false``: version 3 will use the filter set names as written. See
`Filter set names`_ below.

Each filter set that you specify has the following options:

Expand All @@ -124,6 +136,7 @@ Each filter set that you specify has the following options:
``filters`` parameter for ``imagepng`` function in `PHP manual`_ for more details)
* ``cache`` - override the default cache setting.
* ``data_loader`` - override the default data loader.
* ``default_image`` - override the default image of this filter set. See `Default image`_ below.
* ``route`` - optional list of route requirements, defaults and options using in
the route loader. Add array with keys ``requirements``, ``defaults`` or ``options``.
Default value: empty array.
Expand All @@ -133,4 +146,60 @@ Each filter set that you specify has the following options:
Imagine (PR pending))


Filter set names
----------------

By default, a filter set name that contains a ``-`` and no ``_`` is renamed by the Symfony
configuration, so ``my-thumbnail`` has to be used as ``my_thumbnail`` in templates and in the URLs.
This normalization is deprecated, and will be removed in version 3. To use your filter set names as
written, set ``normalize_filter_set_names`` to ``false``, and make sure the names in your
configuration match the names used in your templates and code literally:

.. code-block:: yaml

liip_imagine:
normalize_filter_set_names: false
filter_sets:
my-thumbnail:
filters:
thumbnail: { size: [120, 90], mode: outbound }

.. code-block:: twig

<img src="{{ asset('/relative/path/to/image.jpg') | imagine_filter('my-thumbnail') }}" />

Names that already contain a ``_``, like ``my-thumbnail_v2``, and names coming from an XML
configuration were never renamed and do not need any change.

Default image
-------------

When the imagine controller can not deliver an image, it redirects to the ``default_image`` of the
requested filter set, falling back to the global ``default_image``. Both are URLs to an existing
image, and both default to ``null``, which disables the mechanism:

.. code-block:: yaml

liip_imagine:
default_image: /images/placeholder.png
filter_sets:
avatar:
default_image: /images/anonymous.png
filters:
thumbnail: { size: [100, 100], mode: outbound }

Which failures are replaced by that image depends on ``controller.debug``:

* A source image that can not be loaded always leads to the default image. This is the common case
of a path that points at nothing.
* An image that the driver fails to process leads to the default image only when
``controller.debug`` is disabled, which by default means outside of the Symfony debug mode. The
exception is then logged with the ``warning`` level, so that an unsupported source file does not
go unnoticed.
* A filter set that does not exist has no default image of its own, so it leads to a not found
response outside of the debug mode, and to an exception in debug mode.

In debug mode the driver failures remain exceptions, so that a file the driver chokes on is visible
while developing instead of silently turning into a placeholder.

.. _`PHP Manual`: https://php.net/imagepng
4 changes: 3 additions & 1 deletion doc/filters/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ Background Options
``bottom``, and ``bottomright``.

**transparency:** ``integer``
Sets the background alpha value. The value should be within a range of 0 (opaque) - 100 (fully transparent).
Sets the background alpha value, from ``0`` (fully transparent) to ``100`` (opaque).
The background is opaque when the option is omitted. Despite its name the value is an
opacity, because it is handed to Imagine as the alpha of the background color.


.. _filter-grayscale:
Expand Down
13 changes: 12 additions & 1 deletion src/Config/Controller/ControllerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,28 @@ final class ControllerConfig

private int $redirectResponseCode;

public function __construct(int $redirectResponseCode)
private bool $debug;

public function __construct(int $redirectResponseCode, bool $debug = true)
{
if (!\in_array($redirectResponseCode, self::REDIRECT_RESPONSE_CODES, true)) {
throw new InvalidArgumentException(\sprintf('Invalid redirect response code "%s" (must be 201, 301, 302, 303, 307, or 308).', $redirectResponseCode));
}

$this->redirectResponseCode = $redirectResponseCode;
$this->debug = $debug;
}

public function getRedirectResponseCode(): int
{
return $this->redirectResponseCode;
}

/**
* Whether failures to generate an image must surface as an error rather than fall back to the default image.
*/
public function isDebug(): bool
{
return $this->debug;
}
}
Loading
Loading