PHPackages                             creative-web-solution/imagine-bundle - 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. creative-web-solution/imagine-bundle

ActiveSymfony-bundle[Image &amp; Media](/categories/media)

creative-web-solution/imagine-bundle
====================================

This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.

2.3.1(5y ago)0170MITPHPPHP ^7.1

Since Feb 13Pushed 3y agoCompare

[ Source](https://github.com/creative-web-solution/LiipImagineBundle)[ Packagist](https://packagist.org/packages/creative-web-solution/imagine-bundle)[ Docs](http://liip.ch)[ RSS](/packages/creative-web-solution-imagine-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (24)Versions (78)Used By (0)

LiipImagineBundle
=================

[](#liipimaginebundle)

Travis-CIStyle-CICoverageDownloadsRelease[![Build Status](https://camo.githubusercontent.com/46decbd0ac51e02a5ef090f57069085b87ae6ce799a8c6cf969d4cb471af2c1d/68747470733a2f2f7472617669732d63692e636f6d2f6c6969702f4c696970496d6167696e6542756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/liip/LiipImagineBundle)[![Style CI](https://camo.githubusercontent.com/a24cf15ab11ad4ee1292d1ba2752e2e6630bc83c934f4f7c978024a1d5d96ae9/68747470733a2f2f7372632e72756e2f736869656c642f6c6969702f4c696970496d6167696e6542756e646c652f322e302f7374796c6563692e737667)](https://src.run/service/liip/LiipImagineBundle/2.0/styleci)[![Coverage](https://camo.githubusercontent.com/795bdb80517baae441d37efed4502b19b02e1ce707909d0a5bf7f3e54cff824c/68747470733a2f2f7372632e72756e2f736869656c642f6c6969702f4c696970496d6167696e6542756e646c652f322e302f636f766572616c6c732e737667)](https://src.run/service/liip/LiipImagineBundle/2.0/coveralls)[![Downloads](https://camo.githubusercontent.com/78a95bd84b3375b2d3680c624abc3238427f7bd520b671769abaf5d60c35a313/68747470733a2f2f7372632e72756e2f736869656c642f6c6969702f4c696970496d6167696e6542756e646c652f7061636b61676973745f64742e737667)](https://src.run/service/liip/LiipImagineBundle/packagist)[![Latest Stable Version](https://camo.githubusercontent.com/494fc6bcb4b3318dd99a24a88b9098893cdd45a07c54199328f270ab80d843d2/68747470733a2f2f7372632e72756e2f736869656c642f6c6969702f4c696970496d6167696e6542756e646c652f7061636b61676973745f762e737667)](https://src.run/service/liip/LiipImagineBundle/packagist)*This bundle provides an image manipulation abstraction toolkit for [Symfony](http://symfony.com/)-based projects.*

Overview
--------

[](#overview)

- [Filter Sets](http://symfony.com/doc/master/bundles/LiipImagineBundle/basic-usage.html): Using any Symfony-supported configuration language (such as YML and XML), you can create *filter set* definitions that specify transformation routines. These definitions include a set of *[filters](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters.html)* and *[post-processors](http://symfony.com/doc/current/bundles/LiipImagineBundle/post-processors.html)*, as well as other optional parameters.
- [Filters](http://symfony.com/doc/master/bundles/LiipImagineBundle/filters.html): Image transformations are applied using *filters*. A set of [build-in filters](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters.html) are provided by the bundle, implementing the most common transformations; examples include [thumbnail](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters/sizing.html#thumbnails), [scale](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters/sizing.html#scale), [crop](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters/sizing.html#cropping-images), [flip](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters/orientation.html#flip), [strip](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters/general.html#strip), and [watermark](http://symfony.com/doc/current/bundles/LiipImagineBundle/filters/general.html#watermark). For more advances transformations, you can easily create your own [custom filters](http://symfony.com/doc/master/bundles/LiipImagineBundle/filters.html#filter-custom).
- [Post-Processors](http://symfony.com/doc/master/bundles/LiipImagineBundle/post-processors.html): Modification of the resulting binary image file (created from your *filters*) are handled by *post-processors*. Examples include [JPEG Optim](http://symfony.com/doc/current/bundles/LiipImagineBundle/post-processors/jpeg-optim.html), [Moz JPEG](http://symfony.com/doc/current/bundles/LiipImagineBundle/post-processors/jpeg-moz.html), [Opti PNG](http://symfony.com/doc/current/bundles/LiipImagineBundle/post-processors/png-opti.html), and [PNG Quant](http://symfony.com/doc/current/bundles/LiipImagineBundle/post-processors/png-quant.html). Just like filters you can easily create your own [custom post-processors](http://symfony.com/doc/master/bundles/LiipImagineBundle/post-processors.html#post-processors-custom).

### Example

[](#example)

Suppose you defined a `my_thumb` filter set, which can be configured to perform any number of different transformations. The simplest invocation would be to pipe the path of your image to the provided `imagine_filter` Twig filter.

```

```

### Contributor Code of Conduct

[](#contributor-code-of-conduct)

This project is released with a [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

### Attribution

[](#attribution)

- Thanks to the many [contributors](https://github.com/liip/LiipImagineBundle/graphs/contributors)who have dedicated their time and code to this project.
- The standalone PHP [Imagine Library](https://github.com/avalanche123/Imagine)is used by this bundle for image transformations.
- This package was forked from [AvalancheImagineBundle](https://github.com/avalanche123/AvalancheImagineBundle)with the goal of making the code more extensible. Reference [AvalancheImagineBundle#25](https://github.com/avalanche123/AvalancheImagineBundle/pull/25)for additional information on the reasoning for this fork.

Setup
-----

[](#setup)

### Installation

[](#installation)

Using this package is similar to all Symfony bundles. The following steps must be performed

1. [Download the Bundle](http://symfony.com/doc/master/bundles/LiipImagineBundle/installation.html#step-1-download-the-bundle)
2. [Enable the Bundle](http://symfony.com/doc/master/bundles/LiipImagineBundle/installation.html#step-2-enable-the-bundle)
3. [Register the Routes](http://symfony.com/doc/master/bundles/LiipImagineBundle/installation.html#step-3-register-the-bundle-s-routes)

Detailed setup instructions can be found in the [installation](http://symfony.com/doc/master/bundles/LiipImagineBundle/installation.html)chapter of the documentation.

### Configuration

[](#configuration)

Detailed information on all available configuration options can be found in the [configuration](http://symfony.com/doc/master/bundles/LiipImagineBundle/configuration.html)chapter of the documentation.

Usage Primer
------------

[](#usage-primer)

Generally, this bundle works by applying *filter sets* to images from inside a template. Your *filter sets* are defined within the application's configuration file (often `app/config/config.yml`) and are comprised of a collection of *filters*, *post-processors*, and other optional parameters.

We'll learn more about *post-processors* and other available parameters later, but for now lets focus on how to define a simple *filter set* comprised of a few *filters*.

### Create Thumbnails

[](#create-thumbnails)

Before we get started, there is a small amount of configuration needed to ensure our [data loaders](http://symfony.com/doc/master/bundles/LiipImagineBundle/data-loaders.html)and [cache resolvers](http://symfony.com/doc/master/bundles/LiipImagineBundle/cache-resolvers.html)operate correctly. Use the following boilerplate in your configuration file.

```
# app/config/config.yml

liip_imagine :

    # configure resolvers
    resolvers :

        # setup the default resolver
        default :

            # use the default web path
            web_path : ~

    # your filter sets are defined here
    filter_sets :

        # use the default cache configuration
        cache : ~
```

With the basic configuration in place, we'll start with an example that fulfills a common use-case: creating thumbnails. Lets assume we want the resulting thumbnails to have the following transformations applied to them:

- Scale and crop the image to 120x90px.
- Add a 2px black border to the scaled image.
- Adjust the image quality to 75.

Adding onto our boilerplate from above, we need to define a *filter set* (which we'll name `my_thumb`) with two *filters* configured: the `thumbnail` and `background`*filters*.

```
# app/config/config.yml

liip_imagine :
    resolvers :
        default :
            web_path : ~

    filter_sets :
        cache : ~

        # the name of the "filter set"
        my_thumb :

            # adjust the image quality to 75%
            quality : 75

            # list of transformations to apply (the "filters")
            filters :

                # create a thumbnail: set size to 120x90 and use the "outbound" mode
                # to crop the image when the size ratio of the input differs
                thumbnail  : { size : [120, 90], mode : outbound }

                # create a 2px black border: center the thumbnail on a black background
                # 4px larger to create a 2px border around the final image
                background : { size : [124, 94], position : center, color : '#000000' }
```

You've now created a *filter set* called `my_thumb` that performs a thumbnail transformation. The `thumbnail` filter sizes the image to the desired width and height (in this example, 120x90px), and its `mode: outbound` option causes the resulting image to be cropped if the input ratio differs. The `background`filter results in a 2px black border by creating a black canvas 124x94px in size, and positioning the thumbnail at its center.

**Note:***A *filter set* can have any number of *filters* defined for it. Simple transformations may only require a single *filter* while complex transformations can have an unlimited number of *filters* defined for them.*

There are a number of additional [filters](http://symfony.com/doc/master/bundles/LiipImagineBundle/filters.html), but for now you can use your newly defined `my_thumb` *filter set* immediately within a template.

*For Twig-based template, use:*

```

```

*Or, for PHP-based template, use:*

```
