Spatie Image Optimizer runs PNG, JPEG, WEBP, AVIF, SVG, and GIF files through installed command-line optimizers. It picks available binaries on the system and can overwrite files or write to a new path.
Overview
Image Optimizer is a PHP package for losslessly or lossily compressing common web image formats by delegating work to external optimization programs. A default optimizer chain inspects the image type and invokes tools such as JpegOptim, Pngquant, Optipng, SVGO, Gifsicle, Cwebp, and avifenc when they are present on the host.
The main API optimizes a file in place or writes results to a separate output path. Callers can set per-optimizer timeouts, customize which tools run and with which flags, plug in custom optimizers, or use self-handling optimizers that call remote APIs instead of local binaries.
Integration notes mention companion packages for Laravel image manipulation, media libraries, and webpage-to-image tools, where an optimize step can be added to existing pipelines. The design goal stated in project materials is to hide shell orchestration and sensible default flags behind a small PHP interface.
Because quality depends on installed binaries, documentation includes OS package manager recipes for Ubuntu, Debian, macOS Homebrew, and Fedora-family systems. Failures in one optimizer can be logged and skipped or surfaced via optional exception behavior.
Key features
- Multi-format image optimization
- Automatic optimizer chain selection
- In-place or separate output path
- Configurable optimizer timeouts
- Custom optimizer and chain support
- Self-handling API optimizers
- PSR-3 optimization logging
- Laravel and WordPress integrations noted
Use cases
- Shrinking assets in PHP web apps
- Batch optimization in deploy scripts
- Media library thumbnail pipelines
- Automated post-processing after uploads