PHPackages                             uxcode-fr/image-optimizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. uxcode-fr/image-optimizer

ActiveLibrary[Image &amp; Media](/categories/media)

uxcode-fr/image-optimizer
=========================

Converts PNG/JPG images to AVIF, WebP and JPG in multiple sizes via Imagick.

1.0.5(1mo ago)67—0%1MITPHPPHP &gt;=8.1

Since Mar 20Pushed 1mo agoCompare

[ Source](https://github.com/uxcode-fr/image-optimizer)[ Packagist](https://packagist.org/packages/uxcode-fr/image-optimizer)[ Docs](https://github.com/uxcode-fr/image-optimizer)[ RSS](/packages/uxcode-fr-image-optimizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (7)Used By (0)

Image Optimizer
===============

[](#image-optimizer)

**Converts PNG/JPG images to AVIF, WebP and JPG in multiple sizes.**

Works with **Laravel**, **Symfony**, and **vanilla PHP** projects.

[![Screenshot](https://raw.githubusercontent.com/uxcode-fr/image-optimizer/main/screenshot.png)](https://raw.githubusercontent.com/uxcode-fr/image-optimizer/main/screenshot.png)

---

Why use it?
-----------

[](#why-use-it)

Modern web performance starts with images. They typically account for **50–80% of a page's total weight** — and they are the first thing Lighthouse, PageSpeed Insights, and Core Web Vitals will flag.

### Next-gen formats

[](#next-gen-formats)

AVIF and WebP deliver the same visual quality as JPEG at a fraction of the size:

FormatTypical size vs JPGJPGbaselineWebP~30% smallerAVIF~50% smallerThe browser automatically picks the best format it supports via `` / `srcset`. JPG is kept as a universal fallback.

### Responsive images &amp; HiDPI

[](#responsive-images--hidpi)

Serving a 1200px image on a 300px thumbnail wastes bandwidth and slows down the page. With this tool you define the exact widths you need per image category, and `@2x` / `@3x` variants are generated automatically for Retina and HiDPI screens — so every device downloads only what it needs.

### PageSpeed &amp; Lighthouse impact

[](#pagespeed--lighthouse-impact)

Optimizing images directly improves the metrics that matter most:

- **LCP (Largest Contentful Paint)** — the main image loads faster
- **Total Blocking Time** — less network contention
- **Serve images in next-gen formats** — the most common PageSpeed recommendation, resolved
- **Properly size images** — resolved by generating the right widths
- **Efficiently encode images** — resolved by tunable per-format quality

### Build-time, zero runtime cost

[](#build-time-zero-runtime-cost)

Images are generated once at build time — no on-the-fly processing, no extra server load, no CDN dependency. The output is plain static files you deploy like any other asset.

---

Prerequisites
-------------

[](#prerequisites)

Requires the **PHP Imagick extension** on your system.

```
# Ubuntu / Debian
sudo apt install -y php-imagick

# macOS
brew install imagemagick && pecl install imagick
```

---

Installation
------------

[](#installation)

```
composer require --dev uxcode-fr/image-optimizer
```

---

Configuration
-------------

[](#configuration)

### Laravel

[](#laravel)

```
php artisan vendor:publish --tag=image-optimizer-config
```

### Symfony / vanilla PHP

[](#symfony--vanilla-php)

```
cp vendor/uxcode-fr/image-optimizer/config/image-optimizer.php config/image-optimizer.php
```

### config/image-optimizer.php

[](#configimage-optimizerphp)

```
return [
    'source'      => 'resources/images',
    'destination' => 'public/img',

    'quality' => [
        'avif' => 60,
        'webp' => 82,
        'jpg'  => 85,
    ],

    'formats'   => ['avif', 'webp', 'jpg'],
    'densities' => [1, 2],

    'folders' => [
        'product' => [200, 280],   // generates -200, -200@2x, -280, -280@2x variants
        'author'  => [48, 128],
        'article' => null,         // convert only, no resize
    ],
];
```

### Via composer.json (fallback)

[](#via-composerjson-fallback)

```
{
  "extra": {
    "image-optimizer": {
      "source": "resources/images",
      "destination": "public/img",
      "quality": { "avif": 60, "webp": 82, "jpg": 85 },
      "formats": ["avif", "webp", "jpg"],
      "densities": [1, 2],
      "folders": {
        "product": [200, 280],
        "author": [48, 128]
      }
    }
  }
}
```

---

Usage
-----

[](#usage)

```
# Process all images
vendor/bin/image-optimizer

# Process only one folder
vendor/bin/image-optimizer --folder=product

# Force regeneration of existing images
vendor/bin/image-optimizer --force

# Delete generated images with no matching source
vendor/bin/image-optimizer --clean
```

### Output example

[](#output-example)

```
🖼️   Optimizing product/hero.png (245 KB)...
  ✓  public/img/product/hero-200.avif (12 KB, -95% 🚀)
  ✓  public/img/product/hero-200.webp (18 KB, -93% 🚀)
  ✓  public/img/product/hero-200.jpg (22 KB, -91% 🚀)
  ✓  public/img/product/hero-200@2x.avif (38 KB, -84% 🚀)
  ✓  public/img/product/hero-200@2x.webp (52 KB, -79% 🚀)
  ✓  public/img/product/hero-200@2x.jpg (61 KB, -75% 🚀)

🖼️   Optimizing author/avatar.png (18 KB)...
  –  public/img/author/avatar-48.avif (skipped)
  –  public/img/author/avatar-48.webp (skipped)
  –  public/img/author/avatar-48.jpg (skipped)

6 image(s) generated, 3 skipped, 0 deleted.

```

---

HTML usage examples
-------------------

[](#html-usage-examples)

### `` with multiple formats and sizes

[](#picture-with-multiple-formats-and-sizes)

```

```

The browser picks the first `` it supports, from top to bottom — AVIF first, then WebP, then JPG as a universal fallback.

### Simple `srcset` (single format, multiple widths)

[](#simple-srcset-single-format-multiple-widths)

```

```

### Avatar (fixed size, HiDPI only)

[](#avatar-fixed-size-hidpi-only)

```

```

### Laravel Blade

[](#laravel-blade)

```

```

---

Configuration options
---------------------

[](#configuration-options)

KeyDefaultDescription`source``resources/images`Source folder (PNG/JPG), relative to project root`destination``public/img`Output folder, relative to project root`quality``['avif'=>60, 'webp'=>82, 'jpg'=>85]`Compression quality per format (1–100)`formats``['avif', 'webp', 'jpg']`Output formats — any subset of `avif`, `webp`, `jpg``densities``[1, 2]`Pixel density multipliers (`1` = base, `2` = @2x…)`folders``[]`Per-folder width list (`null` = convert only)### Obsolete image cleanup

[](#obsolete-image-cleanup)

Pass `--clean` to delete generated files that no longer have a matching source image (only for folders declared in `folders`).

---

License
-------

[](#license)

MIT — Copyright 2026 [uxcode.fr](https://uxcode.fr)

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance97

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

49d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2384dbfafc7589f7d07b0f19083a03d7d1b4f7e15f00468261d427e0a1925c10?d=identicon)[arnolem](/maintainers/arnolem)

---

Top Contributors

[![arnolem](https://avatars.githubusercontent.com/u/2263103?v=4)](https://github.com/arnolem "arnolem (13 commits)")

---

Tags

devimageoptimizationresponsiveWebpavif

### Embed Badge

![Health badge](/badges/uxcode-fr-image-optimizer/health.svg)

```
[![Health](https://phpackages.com/badges/uxcode-fr-image-optimizer/health.svg)](https://phpackages.com/packages/uxcode-fr-image-optimizer)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M560](/packages/symfony-maker-bundle)[ps/image-optimizer

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

9341.7M25](/packages/ps-image-optimizer)[joshembling/image-optimizer

Optimize your Filament images before they reach your database.

111145.4k12](/packages/joshembling-image-optimizer)[somehow-digital/typo3-media-processing

Media Processing

101.1k](/packages/somehow-digital-typo3-media-processing)[spacecatninja/imager-x

Ninja powered image transforms.

29390.0k23](/packages/spacecatninja-imager-x)[heyday/silverstripe-responsive-images

Configure and send a series of image size options to the client without loading any resources until a media query can be executed.

5387.7k6](/packages/heyday-silverstripe-responsive-images)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
