- How do I install ps/image-optimizer in a Laravel application?
- Install it with Composer using composer require ps/image-optimizer. Symfony Process is already present transitively in Laravel, so no dependency conflicts are expected. There is no service provider or publishable config, so you simply instantiate the optimizer chain where you need it, ideally behind your own interface.
- Does ps/image-optimizer support Laravel 10, Laravel 11, and PHP 8.2 or 8.3?
- The library is framework-agnostic, so Laravel version is not a constraint; what matters is the PHP version constraint on the tag you install. Check the constraint on the latest release against your target runtime before committing, because older tags cap at PHP 7 and would force a fork. Pin a version that explicitly supports PHP 8.2 or 8.3 and verify it in CI.
- Which binaries do I need to install for ps/image-optimizer to work?
- It shells out to native tools such as jpegoptim, optipng, pngquant, gifsicle, cwebp, and svgo, and only the ones you actually wire into the chain are required. All of them must exist at known absolute paths inside every container that runs optimization, including app containers, worker containers, and CI. Provision them in your base image so runtime environments cannot drift apart.
- Should I run image optimization in a queued job instead of the request?
- Yes. Optimization is blocking, CPU-bound work, so running it inline will show up as a p95 latency regression on uploads. Dispatch a queued job that stores the optimized file and updates the record when finished. Also isolate the process in a resource-limited worker rather than a web request, since it invokes external binaries against user-supplied files.
- Is ps/image-optimizer a Laravel package with a facade and config file?
- No. It is a framework-agnostic PHP orchestration library with no service provider, facade, publishable config, queue hook, or events. Its surface is a small composition API: build an OptimizerChain from optimizer objects and call optimize with a source and destination. For Laravel, wrap it behind a domain-owned contract so swapping to another implementation later does not touch call sites.
- How do I chain multiple optimizers and control compression quality?
- You create optimizer instances such as Optipng, Pngquant, or Jpegoptim, add them to an OptimizerChain, and run the chain against a file. Each optimizer exposes its own options for quality and metadata stripping, with sensible defaults, so you can combine lossless and lossy passes per format. Keep the chain configuration in one place so quality thresholds are easy to audit and change.
- Can I write a custom optimizer or handle WebP and AVIF with this library?
- Custom optimizers are supported through simple interfaces, so you can wrap any CLI tool you need, including cwebp for WebP via the built-in optimizer. AVIF is not addressed by this toolchain, and the library does not resize, crop, or transcode formats beyond what the underlying binaries do. Treat it as a compression step rather than the terminal state for modern format support.
- Is it safe to optimize user-uploaded images with ps/image-optimizer?
- The library invokes external processes against user-supplied files, so decompression bombs, malformed inputs, and metadata or PII passing through CLI arguments need explicit handling. Run optimization in an isolated, resource-limited worker, never on the web request path, and validate uploads before they reach the optimizer. Also confirm your legal position on invoking GPL binaries such as gifsicle and pngquant as separate processes.
- How do I test image optimization in a Laravel test suite?
- The library is designed to be testable and raises clear exceptions, so unit tests can assert on optimizer behavior without hitting real binaries by injecting a fake optimizer into the chain. For feature tests, bind a stub implementation of your own ImageOptimizer contract in the container so upload flows do not depend on native tooling. Keep a small set of integration tests that run the real binaries in CI to catch environment drift.
- How does ps/image-optimizer compare to Spatie image-optimizer or Intervention Image, and is it maintained?
- Spatie image-optimizer is a Laravel wrapper around this same concept, while Intervention Image handles resizing and manipulation rather than compression. Choose based on whether you want a Laravel-flavored package or a framework-agnostic adapter you control. Be aware that ps/image-optimizer is in low-maintenance mode, so verify the PHP constraint on the latest tag and plan for a possible fork; the near-zero dependent count is a weak but real health signal.