PHPackages                             bvtterfly/lio - 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. bvtterfly/lio

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

bvtterfly/lio
=============

Easily optimize images using Laravel

2.0.1(3y ago)621905[5 PRs](https://github.com/bvtterfly/lio/pulls)MITPHPPHP ^8.0

Since Feb 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/bvtterfly/lio)[ Packagist](https://packagist.org/packages/bvtterfly/lio)[ Docs](https://github.com/bvtterfly/lio)[ GitHub Sponsors](https://github.com/bvtterfly)[ RSS](/packages/bvtterfly-lio/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (14)Versions (13)Used By (0)

🚨 THIS PACKAGE HAS BEEN ABANDONED 🚨

I no longer use Laravel and cannot justify the time needed to maintain this package. That's why I have chosen to abandon it. Feel free to fork my code and maintain your own copy.

Easily optimize images using Laravel
====================================

[](#easily-optimize-images-using-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4735b15db7ccb875b2be92afac090c07a127a11c35298ee81663b1538245c505/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f627674746572666c792f6c696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bvtterfly/lio)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ac96fcd4b82aa5b4e4a1c522aec360a1e71063d3963dc7fcad6c116852346006/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f627674746572666c792f6c696f2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/bvtterfly/lio/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/702d818d04b956677196e7ec379d592b62aa9fb2b43a0ff857f692a5058f36d0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f627674746572666c792f6c696f2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/bvtterfly/lio/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/dbf5d569acc5395a1ca0952eb794e41502028b44c9a5eed3b9b10a0d357d9b66/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f627674746572666c792f6c696f3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bvtterfly/lio)

Lio can optimize PNGs, JPGs, SVGs, and GIFs by running them through a chain of various [image optimization tools](https://github.com/bvtterfly/lio#command-line-optimization-tools).

This package is heavily based on `Spatie`'s `spatie/image-optimizer` and `spatie/laravel-image-optimizer` packages and can optimize local images like them. In addition, It optimizes images stored on the Laravel filesystem disks.

Here's how you can use it:

```
use Bvtterfly\Lio\Facades\ImageOptimizer;
// The image from your configured filesystem disk will be downloaded, optimized, and uploaded to the output path in
ImageOptimizer::optimize($pathToImage, $pathToOptimizedImage);
// The local image will be replaced with an optimized version which should be smaller
ImageOptimizer::optimizeLocal($pathToImage);
// if you use a second parameter the package will not modify the original
ImageOptimizer::optimizeLocal($pathToImage, $pathToOptimizedImage);
```

If you don't like facades, just resolve a configured instance of `Bvtterfly\Lio\OptimizerChain` out of the container:

```
use Bvtterfly\Lio\OptimizerChain;
app(OptimizerChain::class)->optimize($pathToImage, $pathToOptimizedImage);
```

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

[](#installation)

You can install the package via composer:

```
composer require bvtterfly/lio
```

The package will automatically register itself.

The package uses a bunch of binaries to optimize images. To learn which ones on how to install them, head over to the [image optimization tools](https://github.com/bvtterfly/lio#command-line-optimization-tools) section.

The package comes with some sane defaults to optimize images. You can modify that configuration by publishing the config file.

```
php artisan vendor:publish --tag="lio-config"
```

This is the contents of the published config file:

```
use Bvtterfly\Lio\Optimizers\Cwebp;
use Bvtterfly\Lio\Optimizers\Gifsicle;
use Bvtterfly\Lio\Optimizers\Jpegoptim;
use Bvtterfly\Lio\Optimizers\Optipng;
use Bvtterfly\Lio\Optimizers\Pngquant;
use Bvtterfly\Lio\Optimizers\ReSmushOptimizer;
use Bvtterfly\Lio\Optimizers\Svgo;
use Bvtterfly\Lio\Optimizers\Svgo2;

return [
    /*
     * If set to `default` it uses your default filesystem disk.
     * You can set it to any filesystem disks configured in your application.
     */
    'disk' => 'default',

    /*
     * If set to `true` all output of the optimizer binaries will be appended to the default log channel.
     * You can also set this to a class that implements `Psr\Log\LoggerInterface`
     * or any log channels you configured in your application.
     */
    'log_optimizer_activity' => false,

    /*
     * Optimizers are responsible for optimizing your image
     */
    'optimizers' => [
        Jpegoptim::class => [
            '--max=85',
            '--strip-all',
            '--all-progressive',
        ],
        Pngquant::class => [
            '--quality=85',
            '--force',
            '--skip-if-larger',
        ],
        Optipng::class => [
            '-i0',
            '-o2',
            '-quiet',
        ],
        Svgo2::class => [],
        Gifsicle::class => [
            '-b',
            '-O3',
        ],
        Cwebp::class => [
            '-m 6',
            '-pass 10',
            '-mt',
            '-q 80',
        ],
//        Svgo::class => [
//            '--disable={cleanupIDs,removeViewBox}',
//        ],
//        ReSmushOptimizer::class => [
//            'quality' => 92,
//            'retry' => 3,
//            'mime' => [
//                'image/png',
//                'image/jpeg',
//                'image/gif',
//                'image/bmp',
//                'image/tiff',
//            ],
//
//            'exif' => false,
//
//        ],
    ],

    /*
    * The maximum time in seconds each optimizer is allowed to run separately.
    */
    'timeout' => 60,

    /*
    * The directories where your binaries are stored.
    * Only use this when your binaries are not accessible in the global environment.
    */
    'binaries_path' => [
        'jpegoptim' => '',
        'optipng' => '',
        'pngquant' => '',
        'svgo' => '',
        'gifsicle' => '',
        'cwebp' => '',
    ],

    /*
    * The directory where the temporary files will be stored.
    */
    'temporary_directory' => storage_path('app/temp'),

];
```

### Command-Line Optimization tools

[](#command-line-optimization-tools)

The package will use these optimizers if they are present on your system:

- [JpegOptim](http://freecode.com/projects/jpegoptim)
- [Optipng](http://optipng.sourceforge.net/)
- [Pngquant 2](https://pngquant.org/)
- [SVGO 2](https://github.com/svg/svgo)
- [Gifsicle](http://www.lcdf.org/gifsicle/)
- [cwebp](https://developers.google.com/speed/webp/docs/precompiled)

Here's how to install all the optimizers on Ubuntu:

```
sudo apt-get install jpegoptim
sudo apt-get install optipng
sudo apt-get install pngquant
sudo npm install -g svgo@2.8.x
sudo apt-get install gifsicle
sudo apt-get install webp
```

And here's how to install the binaries on MacOS (using [Homebrew](https://brew.sh/)):

```
brew install jpegoptim
brew install optipng
brew install pngquant
npm install -g svgo@2.8.x
brew install gifsicle
brew install webp
```

And here's how to install the binaries on Fedora/RHEL/CentOS:

```
sudo dnf install epel-release
sudo dnf install jpegoptim
sudo dnf install optipng
sudo dnf install pngquant
sudo npm install -g svgo@2.8.x
sudo dnf install gifsicle
sudo dnf install libwebp-tools
```

> If You can't install and use above optimizers, You can still optimize your images using [reSmush Optimizer](https://github.com/bvtterfly/lio#resmush-optimizer).

Which tools will do what?
-------------------------

[](#which-tools-will-do-what)

The package will automatically decide which tools to use on a particular image.

### JPGs

[](#jpgs)

JPGs will be made smaller by running them through [JpegOptim](http://freecode.com/projects/jpegoptim). These options are used:

- `-m85`: this will store the image with 85% quality. This setting [seems to satisfy Google's Pagespeed compression rules](https://webmasters.stackexchange.com/questions/102094/google-pagespeed-how-to-satisfy-the-new-image-compression-rules)
- `--strip-all`: this strips out all text information such as comments and EXIF data
- `--all-progressive`: this will make sure the resulting image is a progressive one, meaning it can be downloaded using multiple passes of progressively higher details.

### PNGs

[](#pngs)

PNGs will be made smaller by running them through two tools. The first one is [Pngquant 2](https://pngquant.org/), a lossy PNG compressor. We set no extra options, their defaults are used. After that we run the image through a second one: [Optipng](http://optipng.sourceforge.net/). These options are used:

- `-i0`: this will result in a non-interlaced, progressive scanned image
- `-o2`: this set the optimization level to two (multiple IDAT compression trials)

### SVGs

[](#svgs)

SVGs will be minified by [SVGO 2](https://github.com/svg/svgo). SVGO's default configuration will be used, with the omission of the `cleanupIDs` plugin because that one is known to cause troubles when displaying multiple optimized SVGs on one page.

Please be aware that SVGO can break your svg. You'll find more info on that in this [excellent blogpost](https://www.sarasoueidan.com/blog/svgo-tools/) by [Sara Soueidan](https://twitter.com/SaraSoueidan).

The default SVGO optimizer (`Svgo2`) is only compatible with SVGO `2.x`. For custom SVGO configuration, you must create [your configuration file](https://github.com/svg/svgo#configuration) and pass its path to the config array:

```
Svgo2::class => [
    'path' => '/path/to/your/svgo/config.js'
]
```

If you installed SVGO `1.x` and can't upgrade to `2.x`, You can uncomment the `Svgo` optimizer in the config file:

```
Svgo::class => [
    '--disable={cleanupIDs,removeViewBox}',
],
// Svgo2::class => [],
```

### GIFs

[](#gifs)

GIFs will be optimized by [Gifsicle](http://www.lcdf.org/gifsicle/). These options will be used:

- `-O3`: this sets the optimization level to Gifsicle's maximum, which produces the slowest but best results

### WEBPs

[](#webps)

WEBPs will be optimized by [Cwebp](https://developers.google.com/speed/webp/docs/cwebp). These options will be used:

- `-m 6` for the slowest compression method in order to get the best compression.
- `-pass 10` for maximizing the amount of analysis pass.
- `-mt` multithreading for some speed improvements.
- `-q 90` Quality factor that brings the least noticeable changes.

(Settings are original taken from [here](https://medium.com/@vinhlh/how-i-apply-webp-for-optimizing-images-9b11068db349))

#### Set Binary Path

[](#set-binary-path)

If your binaries are not accessible in the global environment, You can set them using `binaries_path` option in the config file.

### reSmush Optimizer

[](#resmush-optimizer)

When you can't install command-line optimizer tools, you can comment them on the config file to disable them and uncomment the reSumsh optimizer to enable it. [reSmush](https://resmush.it/) provides a free API for optimizing images. However, it can only optimize up to 5MB of PNG, JPG, GIF, BMP, and TIF images.

Usage
-----

[](#usage)

You can resolve a configured instance of `Bvtterfly\Lio\OptimizerChain` out of the container:

```
use Bvtterfly\Lio\OptimizerChain;
app(OptimizerChain::class)->optimize($pathToImage, $pathToOptimizedImage);
```

or using facade:

```
use Bvtterfly\Lio\Facades\ImageOptimizer;
// The image from your configured filesystem disk will be downloaded, optimized, and uploaded to the output path in
ImageOptimizer::optimize($pathToImage, $pathToOptimizedImage);
```

if your files are local you can using `optimizeLocal` method:

```
use Bvtterfly\Lio\Facades\ImageOptimizer;
// The local image will be replaced with an optimized version which should be smaller
ImageOptimizer::optimizeLocal($pathToImage);
// if you use a second parameter the package will not modify the original
ImageOptimizer::optimizeLocal($pathToImage, $pathToOptimizedImage);
```

### Using the middleware

[](#using-the-middleware)

If you want to optimize all uploaded images in requests to route automatically, You can use the `OptimizeUploadedImages` middleware.

```
Route::middleware(OptimizeUploadedImages::class)->group(function () {
    // all images will be optimized automatically
    Route::post('images', 'ImageController@store');
});
```

### Writing a custom optimizers

[](#writing-a-custom-optimizers)

You may want to write your own optimizer to optimize your images via other utilities. An optimizer is any class that implements the `Bvtterfly\Lio\Contracts\Optimizer` interface:

```
use Psr\Log\LoggerInterface;

interface Optimizer
{
    /**
     * Determines if the given image can be handled by the optimizer.
     *
     * @param Image $image
     *
     * @return bool
     */
    public function canHandle(Image $image): bool;

    /**
     * Sets the path to the image that should be optimized.
     *
     * @param string $imagePath
     *
     * @return Optimizer
     */
    public function setImagePath(string $imagePath): self;

    /**
     * Sets the logger for logging optimization process.
     *
     * @param  LoggerInterface  $logger
     *
     * @return Optimizer
     */
    public function setLogger(LoggerInterface $logger): self;

    /**
     * Sets the amount of seconds optimizer may use.
     *
     * @param  int  $timeout
     *
     * @return Optimizer
     */
    public function setTimeout(int $timeout): self;

    /**
     * Runs the optimizer.
     *
     * @return void
     */
    public function run(): void;
}
```

If you want to view an example implementation take a look at [the existing optimizers](https://github.com/bvtterfly/lio/tree/main/src/Optimizers) shipped with this package. You can add the fully qualified classname of your optimizer as a key in the `optimizers` array in the config file.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [ARI](https://github.com/bvtterfly)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 64.1% 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 ~19 days

Recently: every ~28 days

Total

7

Last Release

1432d ago

Major Versions

0.2.1 → 1.0.02022-05-26

1.0.0 → 2.0.02022-06-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/99682351?v=4)[Λгi](/maintainers/bvtterfly)[@bvtterfly](https://github.com/bvtterfly)

---

Top Contributors

[![bvtterfly](https://avatars.githubusercontent.com/u/99682351?v=4)](https://github.com/bvtterfly "bvtterfly (41 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (10 commits)")

---

Tags

laravellaravel-image-optimizerbvtterflylio

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/bvtterfly-lio/health.svg)

```
[![Health](https://phpackages.com/badges/bvtterfly-lio/health.svg)](https://phpackages.com/packages/bvtterfly-lio)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[saasykit/laravel-open-graphy

An awesome open graph image (social cards) generator package for Laravel.

13057.0k](/packages/saasykit-laravel-open-graphy)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[finller/laravel-media

A flexible media library for Laravel

472.1k](/packages/finller-laravel-media)[ace-of-aces/laravel-image-transform-url

Easy, URL-based image transformations inspired by Cloudflare Images.

1756.4k](/packages/ace-of-aces-laravel-image-transform-url)

PHPackages © 2026

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