Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Image Optim Bundle Laravel Package

wearejust/image-optim-bundle

A Symfony bundle for optimizing images through configurable filters and processors. Integrates with Symfony's service container to compress, resize, and cache uploaded images, with Twig helpers and support for multiple image drivers. Lightweight and framework-native.

View on GitHub
Deep Wiki
Context7

Getting Started

First, calibrate expectations: wearejust/image-optim-bundle is a Symfony bundle, not a Laravel package, last released in September 2017, archived, with 1 star and 0 dependents. There is no service provider, no facade, no config/image-optim.php to publish. If you are on Laravel, treat this as reference source code, not a dependency.

Minimal evaluation path:

  1. Read the repo in this order: README.md → composer.json (PHP/Symfony constraints) → DependencyInjection/Configuration.php (what is actually configurable) → Resources/config/services.* (what the container wires up) → Command/ and any EventSubscriber/ or EventListener/.
  2. Note the external binary it shells out to. Image-optimization bundles of this era almost always wrap a CLI tool (jpegoptim, optipng, pngquant, or the macOS-only imageoptim). The README will name it; if it doesn't, grep the source for exec, shell_exec, Process, or Symfony\Component\Process.
  3. Do not composer require it into a Laravel app. Clone it into a scratch Symfony skeleton only if you genuinely need to see it run, or just read the source.
  4. First use case to reason about: a post-upload hook that optimizes an image before it lands in storage, and a console command that batch-optimizes an existing directory of assets.

The realistic takeaway from "Getting Started" is: you are reading this to learn the shape of an image-optimization integration, not to install it.

Implementation Patterns

What the bundle does (or was intended to do) in Symfony terms, translated to how you would actually use it day-to-day:

  • Service injection into an upload handler. The bundle exposes an optimizer service you inject into a controller or upload service. In a Laravel port you would bind this as a singleton (or better, a small dedicated class) in a service provider and inject it into your upload action or a StoreUploadedImage action class.
  • Post-upload optimization, not in-request. Optimizing a 4 MB JPEG synchronously in the HTTP request is how you get 30-second uploads. The pattern worth copying is: accept the upload, store the original, dispatch a queued job (OptimizeImageJob) that runs the binary and replaces the file or writes a derived version. The original bundle's event-listener style maps cleanly onto a Laravel queued listener.
  • Batch/console command. The bundle's Command/ directory is the most portable idea: iterate a directory, skip already-optimized files (by mtime or a hash sidecar), run the binary, log failures. In Laravel this becomes an artisan command over a Storage disk, ideally chunked and resumable.
  • Config-driven binary paths and quality. Symfony bundle config typically exposes things like binary path, quality level, and which formats to process. In Laravel you would put these in config/image-optim.php and read them via config(). Keep defaults conservative (quality ~80–85, lossless for PNG where possible) and make them per-format.
  • Idempotency and caching. Before optimizing, check whether the output already exists and is newer than the source. Store a hash or size marker. This is the single biggest operational win and is usually missing from bundles this age.
  • Decorator/alias replacement. If you do end up using it in Symfony, the intended extension point is overriding the service alias in services.yaml with your own implementation. In Laravel the equivalent is binding an interface to your own class and ignoring the bundle entirely.
  • Format handling. Treat JPEG, PNG, and (if the binary supports it) WebP/GIF as separate pipelines with separate binaries. Do not assume one binary handles all formats.

A pragmatic Laravel-native shape, if you are lifting ideas:

  1. App\Services\ImageOptimizer with an optimize(string $absolutePath): void method that shells out via Symfony\Component\Process\Process (usable in Laravel).
  2. App\Jobs\OptimizeImage queued job wrapping it, with $tries and $backoff.
  3. php artisan images:optimize {disk} {path} command for backfill.
  4. Config file for binary paths and quality.

That is roughly 100 lines and will be maintainable in a way this bundle will not be.

Gotchas and Tips

  • Archived and unmaintained. No security patches, no PHP 8 compatibility work, no Symfony 5+/6+ support. Installing it in 2024+ is a supply-chain and runtime liability. composer require will likely fail on modern PHP constraints anyway.
  • Wrong framework. There is no Laravel integration. No ImageOptimServiceProvider, no facade, no publishable config. Any "installation" instructions in the README are Symfony AppKernel/bundles.php steps you cannot follow directly.
  • Binary dependency is the real hidden cost. The bundle optimizes nothing itself. If optipng/jpegoptim/imageoptim is not on the server, you get silent no-ops or opaque process exceptions. Verify the binary exists and is executable at deploy time (a health-check route or a boot-time assertion), not at first user upload.
  • Path semantics. Symfony bundles assume absolute filesystem paths. Laravel's Storage::path() differs per driver; S3 has no local path at all. If you need S3, the binary approach breaks down — you must download to a temp file, optimize, re-upload. Plan for that explicitly.
  • Permissions and temp dirs. The web/queue user must be able to write to the target directory and to whatever temp dir the binary uses (sys_get_temp_dir()). This is the most common production failure.
  • Timeouts and memory. Large images can hang a worker. Set a hard timeout on the process call and a max file size guard. Never run this in a synchronous HTTP request.
  • Debugging. Reproduce outside PHP first: run the exact binary command against the exact file manually. If that works, the bug is in your path or process invocation. Log the full command line and exit code.
  • Idempotency failures. Running the optimizer twice should be a no-op. Many simple wrappers re-encode the file each time, degrading quality. Verify with a checksum after a second run.
  • Extension points are thin. Realistically there is one useful seam: replace the optimizer service with your own implementation. Don't fight the bundle's wiring; write the ~100-line service described above.
  • Better alternatives for Laravel: spatie/image-optimizer (wraps the same binaries, actively maintained, framework-agnostic), intervention/image (manipulation + encoding, not binary-based), or a hosted API (TinyPNG, Cloudflare Images, imgix) if you want to offload the problem entirely. For pure "shrink what I uploaded," spatie/image-optimizer is the direct replacement.
  • If you must cite this package: cite it as prior art for the pattern (post-upload queue + binary + console backfill), not as a dependency. One star and zero dependents is a signal, not a coincidence.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource