zenstruck/imagine-extra-bundle
A Symfony bundle that adds extra filters and utilities to the Imagine image manipulation library, making it easy to apply additional image transformations through configuration and services.
Before anything else: this bundle is archived, last released in December 2014, and targets Symfony2 / PHP 5.x. Its purpose was to wire the standalone imagine-filters library (filter definitions + a filesystem cache) into a Symfony2 application, giving you a service and a Twig helper that turn a source image path into a cached, transformed derivative. Treat this write-up as "how it was used" and "what to do instead," not as a recommendation to install it on a current project.
If you are maintaining a legacy Symfony2 app where it is already installed, the minimal path is:
imagine/imagine with either the GD or Imagick driver) and ensure the driver's PHP extension is present. The bundle does not ship an image backend.Zenstruck\ImagineExtraBundle\ZenstruckImagineExtraBundle in app/AppKernel.php and the routing/DI config if the README asks for it.config.yml.web/, then in a controller or template ask the bundle for the derivative of a given filter name (thumbnail, preview, etc.) and render the returned web-relative path in an <img> tag.Where to look first in the repo:
README.md — the only real documentation; read the config example before reading code.DependencyInjection/ZenstruckImagineExtraExtension.php — the authoritative list of config keys, defaults, and service IDs. This is where you learn what is actually configurable versus what the README promises.Resources/config/*.xml — the service wiring, which tells you which classes you can inject and override.Configuration-defined filter sets. The core workflow is declarative: define each filter once in YAML (a name plus an ordered list of transformations — resize, thumbnail, crop, quality, format), then reference it by name from application code. Keep filter names semantic (product_thumb, hero_wide) rather than technical (resize_200x200), because the name is the cache key and the call site should not change when the dimensions do.
Controller/service usage. Inject the bundle's filter/manager service into a controller or a dedicated image service rather than resolving it from the container. The typical pattern is: accept the upload, save the original, then lazily request the derivative only when it is needed for display. Generating derivatives on upload (eager) is faster to render but multiplies storage and slows the upload request; generating on first render (lazy) is the default and usually correct.
Twig helper for templates. The bundle's Twig function is where most day-to-day usage lives — pass the source path and the filter name, get back a URL. Wrap it in a project-local Twig macro so that every <img> in the app goes through one place; when you eventually migrate away from this bundle, you change one macro instead of grepping templates.
Compose with upload/storage bundles. In practice this bundle was almost always paired with VichUploaderBundle or a Gaufrette/filesystem abstraction. The pattern: the upload bundle owns the original file and its path; the imagine-extra bundle owns only the derivative and its cache path. Keep those two path namespaces strictly separate and never let the derivative path be written back into the entity — derivatives are disposable and must be regenerable.
Runtime filters vs. configured filters. If the library supports passing transformations at call time, resist using that in application code. Ad-hoc transformations bypass the named-filter cache key discipline and lead to an unbounded number of cached derivatives. If you genuinely need dynamic sizing (responsive images), enumerate the allowed sizes in config and map request parameters onto those names.
Testing. Because the filtering itself is delegated to imagine-filters and Imagine, unit-test your code against a stubbed filter/manager service that returns a known path string. Don't assert on actual pixel output in your app's test suite; that belongs in a thin integration test with a fixture image, and it will be slow and driver-dependent.
imagine-filters used directly behind a small service of your own.--ignore-platform-reqs hacks will surface as fatal errors at runtime. If you need this code, vendor it or fork it.cache:clear does not clear images. Symfony's cache clear is unrelated to the image cache. Add an explicit console command or deploy step for the image cache directory, and give that directory its own deploy-time permissions story — a read-only or missing directory produces silent 404s, not exceptions.memory_limit mid-request; GD silently degrades quality on some formats and mishandles palette PNGs. Set an explicit memory_limit consideration and test with your largest real-world images, not a 200×200 fixture.web/. Nine out of ten issues are one of the first two.imagine-filters filter interface (registered in DI), a custom cache/resolver class, and overriding the Twig extension service. Those are the three places worth patching rather than editing the bundle in place.composer.json is to schedule replacement with LiipImagineBundle and keep the named-filter vocabulary intact so templates and config translate almost one-to-one.How can I help you explore Laravel packages today?