Download the PHP package liip/imagine-bundle without Composer
On this page you can find all versions of the php package liip/imagine-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download liip/imagine-bundle
More information about liip/imagine-bundle
Files in liip/imagine-bundle
Package imagine-bundle
Short Description This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.
License MIT
Homepage https://www.liip.ch
Informations about the package imagine-bundle
LiipImagineBundle
PHPUnit | PHP-CS-Fixer | Coverage | Downloads | Release |
---|---|---|---|---|
This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.
Overview
-
Filter Sets: 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 and post-processors, as well as other optional parameters.
-
Filters: Image transformations are applied using filters. A set of build-in filters are provided by the bundle, implementing the most common transformations; examples include thumbnail, scale, crop, flip, strip, and watermark. For more advances transformations, you can easily create your own custom filters.
- Post-Processors: Modification of the resulting binary image file (created from your filters) are handled by post-processors. Examples include JPEG Optim, Moz JPEG, Opti PNG, and PNG Quant. Just like filters you can easily create your own custom post-processors.
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
This project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Attribution
-
Thanks to the many contributors who have dedicated their time and code to this project.
-
The standalone PHP Imagine Library is used by this bundle for image transformations.
- This package was forked from AvalancheImagineBundle with the goal of making the code more extensible. Reference AvalancheImagineBundle#25 for additional information on the reasoning for this fork.
Setup
Installation
Using this package is similar to all Symfony bundles. The following steps must be performed
Detailed setup instructions can be found in the installation chapter of the documentation.
Configuration
Detailed information on all available configuration options can be found in the configuration chapter of the documentation.
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
Before we get started, there is a small amount of configuration needed to ensure our data loaders and cache resolvers operate correctly. Use the following boilerplate in your configuration file.
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.
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,
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:
Behind the scenes, the bundle applies the filter(s) to the image on-the-fly
when the first page request is served. The transformed image is then cached
for subsequent requests. The final cached image path would be similar to
/media/cache/my_thumb/relative/path/to/image.jpg
.
Note:
*Using the dev
environment you might find that images are not properly
rendered via the template helper. This is often caused by having
intercept_redirect
enabled in your application configuration. To ensure
images are rendered, it is strongly suggested to disable this option:
Runtime Options
Sometime, you may have a filter defined that fulfills 99% of your usage scenarios. Instead of defining a new filter for the erroneous 1% of cases, you may instead choose to alter the behavior of a filter at runtime by passing the template helper an options array.
For Twig-based template, use:
Or, for PHP-based template, use:
Path Resolution
Sometime you need to resolve the image path returned by this bundle for a filtered image. This can easily be achieved using Symfony's console binary or programmatically from within a controller or other piece of code.
Resolve with the Console
You can resolve an image URL using the console command
liip:imagine:cache:resolve
. The only required argument is one or more
relative image paths (which must be separated by a space).
Additionally, you can use the --filter
option to specify which filter
you want to resolve for (if the --filter
option is omitted, all
available filters will be resolved).
Resolve Programmatically
You can resolve the image URL in your code using the getBrowserPath
method of the liip_imagine.cache.manager
service. Assuming you already
have the service assigned to a variable called $imagineCacheManager
,
you would run:
Often, you need to perform this operation in a controller. Assuming your
controller inherits from the base Symfony controller, you can take advantage
of the inherited get
method to request the liip_imagine.cache.manager
service, from which you can call getBrowserPath
on a relative image
path to get its resolved location.
Filters
This bundle provides a set of built-in filters and you may easily define your own filters as well. Reference the filters chapter from our documentation.
Use as a Service
If you need to use your defined "filter sets" from within your controller, you can fetch this bundle's FilterService from the service container to do the heavy lifting for you.
Data Roots
By default, Symfony's web/
directory is registered as a data root to load
assets from. For many installations this will be sufficient, but sometime you
may need to load images from other locations. To do this, you must set the
data_root
parameter in your configuration (often located at app/config/config.yml
).
As of version 1.7.2
you can register multiple data root paths, and the
file locator will search each for the requested file.
As of version 1.7.3
you ask for the public resource paths from all registered bundles
to be auto-registered as data roots. This allows you to load assets from the
Resources/public
folders that reside within the loaded bundles. To enable this
feature, set the bundle_resources.enabled
configuration option to true
.
If you want to register some of the Resource/public
folders, but not all, you can do
so by blacklisting the bundles you don't want registered or whitelisting the bundles you
do want registered. For example, to blacklist (not register) the bundles "FooBundle" and
"BarBundle", you would use the following configuration.
Alternatively, if you want to whitelist (only register) the bundles "FooBundle" and "BarBundle", you would use the following configuration.
Permissions
Image locations must be readable by your web server. On a system that supports
setfacl
(such as Linux/BSD), use
See the Symfony Permissions documentation for commands compatible with macOS and other environments.
Using Apache
You need to grant read access for Apache by adding the following to your Apache VHost configuration
Alternatively, you can place the directive in a separate file within your
project, and include it within your Apache VHost configuration. For example,
you can create the file app/config/apache/photos.xml
and add the following
to your VHost file
This method keeps the file with the rest of your code, allowing you to change it easily or create different environment-dependent configuration files.
Once you have configured Apache properly, the relative path to an image with
the following absolute path /path/to/source/images/dir/logo.png
must be
/FavouriteAlias/logo.png
.
Documentation
For more detailed information about the features of this bundle, refer to the documentation.
All versions of imagine-bundle with dependencies
ext-mbstring Version *
imagine/imagine Version ^1.3.2
symfony/filesystem Version ^3.4|^4.4|^5.3|^6.0|^7.0
symfony/finder Version ^3.4|^4.4|^5.3|^6.0|^7.0
symfony/framework-bundle Version ^3.4.23|^4.4|^5.3|^6.0|^7.0
symfony/mime Version ^4.4|^5.3|^6.0|^7.0
symfony/options-resolver Version ^3.4|^4.4|^5.3|^6.0|^7.0
symfony/process Version ^3.4|^4.4|^5.3|^6.0|^7.0
twig/twig Version ^1.44|^2.9|^3.0