← Tool directory
TOOL PROFILE

Spatie Image Optimizer

Compress editorial images in a PHP publishing pipeline while preserving the original file for comparison.

Open source

Community support

Upvotes come from SearchEngineAnswer members. GitHub stars and reader reviews are counted separately.

Claim this tool if you maintain it.

Best for
Performance
Setup required
Use PHP and Composer plus the binary for the chosen format. The JPEG example uses jpegoptim installed on the system path.
Costs to check
MIT-licensed PHP library. The example runs locally and depends on a separately installed optimizer.
License in catalog
MIT

GitHub repository

GitHub stars
2,882
Forks
225
Last push
2026-11-05
Primary language
PHP

GitHub snapshot from . Stars count GitHub bookmarks. Reader ratings appear separately below.

How to install Spatie Image Optimizer

  1. In a scratch Composer project run composer require spatie/image-optimizer.
    composer require spatie/image-optimizer
  2. Install jpegoptim with your system package manager and confirm jpegoptim --version works under the same account that will run PHP.

First tutorial for Spatie Image Optimizer

  1. Place a representative original JPEG named hero.jpg beside the example script. Keep the source file available.
    <?php
    require __DIR__ . '/vendor/autoload.php';
    
    use Spatie\ImageOptimizer\OptimizerChainFactory;
    
    OptimizerChainFactory::create()
        ->optimize('hero.jpg', 'hero-optimized.jpg');
    
    printf(
        "Original: %d bytes
    Output: %d bytes
    ",
        filesize('hero.jpg'),
        filesize('hero-optimized.jpg')
    );
  2. Save the PHP code as optimize.php and run php optimize.php. Confirm that hero-optimized.jpg exists and the original remains intact.
  3. Compare source and output byte counts and dimensions. Examine a high-detail area before choosing a size threshold or publishing the derivative.

Documentation reviewed on November 20, 2026. The tutorial is a proposed check with illustrative files and URLs.

Official installation and usage documentation ↗

Where Spatie Image Optimizer fits

Use this library when a PHP import or publishing job needs a repeatable optimization step for images it already processes.

When to choose another tool
Use a browser tool such as Squoosh for a one-off comparison where an editor wants to tune quality interactively.
First evaluation
Process one original JPEG into a separate output file and compare byte counts, image dimensions and fine detail.
How to interpret the result
A smaller file can still lose important detail or metadata. Confirm the served derivative and review labels, edges and colors before adopting it.

Reviews and discussion

Reader reviews

Be the first to share your experience with this tool.

Discussion

Ask a question or share a setup tip.

Write a review or join the discussion

Reviews should describe your own experience. All submissions are moderated.

Flag an outdated detail

Include the field that needs updating and a source link. Copy your draft, then use the corrections policy to contact the editorial team.