All Projects → spatie → Laravel Image Optimizer

spatie / Laravel Image Optimizer

Licence: mit
Optimize images in your Laravel app

Projects that are alternatives of or similar to Laravel Image Optimizer

Laravel S
LaravelS is an out-of-the-box adapter between Swoole and Laravel/Lumen.
Stars: ✭ 3,479 (+298.51%)
Mutual labels:  laravel, performance
Enlightn
Your performance & security consultant, an artisan command away.
Stars: ✭ 378 (-56.7%)
Mutual labels:  laravel, performance
Laravel Glide
Easily convert images with Glide
Stars: ✭ 333 (-61.86%)
Mutual labels:  laravel, image
Laravel Varnish
Making Varnish and Laravel play nice together
Stars: ✭ 291 (-66.67%)
Mutual labels:  laravel, performance
Laravel Pjax
A pjax middleware for Laravel
Stars: ✭ 487 (-44.22%)
Mutual labels:  laravel, performance
Borgert Cms
Borgert is a CMS Open Source created with Laravel Framework 5.6
Stars: ✭ 298 (-65.86%)
Mutual labels:  laravel, image
Sharp
High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
Stars: ✭ 21,131 (+2320.5%)
Mutual labels:  image, performance
Meter
Laravel package to find performance bottlenecks in your laravel application.
Stars: ✭ 204 (-76.63%)
Mutual labels:  laravel, performance
Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+2372.74%)
Mutual labels:  laravel, performance
Performance
⏱ PHP performance tool analyser your script on time, memory usage and db query. Support Laravel and Composer for web, web console and command line interfaces.
Stars: ✭ 429 (-50.86%)
Mutual labels:  laravel, performance
Sqip
"SQIP" (pronounced \skwɪb\ like the non-magical folk of magical descent) is a SVG-based LQIP technique.
Stars: ✭ 3,074 (+252.12%)
Mutual labels:  image, performance
Laravel Imageup
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image
Stars: ✭ 646 (-26%)
Mutual labels:  laravel, image
Swissarmylib
Collection of helpful utilities we use in our Unity projects.
Stars: ✭ 154 (-82.36%)
Mutual labels:  optimize, performance
Imageoptim Cli
Make optimisation of images part of your automated build process
Stars: ✭ 3,215 (+268.27%)
Mutual labels:  optimize, performance
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+223.14%)
Mutual labels:  laravel, performance
Tifig
A fast HEIF image converter aimed at thumbnailing
Stars: ✭ 345 (-60.48%)
Mutual labels:  image, performance
Laravel Mix Preload
Add preload and prefetch links based your Mix manifest
Stars: ✭ 162 (-81.44%)
Mutual labels:  laravel, performance
Laravel Partialcache
Blade directive to cache rendered partials in laravel
Stars: ✭ 205 (-76.52%)
Mutual labels:  laravel, performance
Laravel Model Cleanup
Clean up unneeded records
Stars: ✭ 388 (-55.56%)
Mutual labels:  laravel, performance
Laravel Binary Uuid
Optimised binary UUIDs in Laravel
Stars: ✭ 523 (-40.09%)
Mutual labels:  laravel, performance

Optimize images in your Laravel app

Latest Version on Packagist Tests Total Downloads

This package is the Laravel 6.0 and up specific integration of spatie/image-optimizer. It can optimize PNGs, JPGs, SVGs and GIFs by running them through a chain of various image optimization tools. The package will automatically detect which optimization binaries are installed on your system and use them.

Here's how you can use it:

use ImageOptimizer;

// the image will be replaced with an optimized version which should be smaller
ImageOptimizer::optimize($pathToImage);

// if you use a second parameter the package will not modify the original
ImageOptimizer::optimize($pathToImage, $pathToOptimizedImage);

You don't like facades you say? No problem! Just resolve a configured instance of Spatie\ImageOptimizer\OptimizerChain out of the container:

app(Spatie\ImageOptimizer\OptimizerChain::class)->optimize($pathToImage);

The package also contains a middleware to automatically optimize all images in an request.

Don't use Laravel you say? No problem! Just use the underlying spatie/image-optimizer directly.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-image-optimizer

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 optimization tools section in the readme of the underlying image-optimizer package. That readme also contains info on what these tools will do to your images.

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

php artisan vendor:publish --provider="Spatie\LaravelImageOptimizer\ImageOptimizerServiceProvider"

This is the contents of the config/image-optimizer file that will be published:

use Spatie\ImageOptimizer\Optimizers\Svgo;
use Spatie\ImageOptimizer\Optimizers\Optipng;
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
use Spatie\ImageOptimizer\Optimizers\Pngquant;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
use Spatie\ImageOptimizer\Optimizers\Cwebp;

return [
    /**
     * When calling `optimize` the package will automatically determine which optimizers
     * should run for the given image.
     */
    'optimizers' => [

        Jpegoptim::class => [
            '-m85', // set maximum quality to 85%
            '--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
        ],

        Pngquant::class => [
            '--force' // required parameter for this package
        ],

        Optipng::class => [
            '-i0', // this will result in a non-interlaced, progressive scanned image
            '-o2',  // this set the optimization level to two (multiple IDAT compression trials)
            '-quiet' // required parameter for this package
        ],

        Svgo::class => [
            '--disable=cleanupIDs' // disabling because it is know to cause troubles
        ],

        Gifsicle::class => [
            '-b', // required parameter for this package
            '-O3' // this produces the slowest but best results
        ],
        
        Cwebp::class => [
            '-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.
        ],
    ],

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

    /**
     * If set to `true` all output of the optimizer binaries will be appended to the default log.
     * You can also set this to a class that implements `Psr\Log\LoggerInterface`.
     */
    'log_optimizer_activity' => false,
];

If you want to automatically optimize images that get uploaded to your application add the \Spatie\LaravelImageOptimizer\Middlewares\OptimizeImages::class in the http kernel.

// app/Http/Kernel.php
protected $routeMiddleware = [
   ...
   'optimizeImages' => \Spatie\LaravelImageOptimizer\Middlewares\OptimizeImages::class,
];

Usage

You can resolve a configured instance of Spatie\ImageOptimizer\OptimizerChain out of the container:

// the image will be replaced with an optimized version which should be smaller
app(Spatie\ImageOptimizer\OptimizerChain::class)->optimize($pathToImage);

// if you use a second parameter the package will not modify the original
app(Spatie\ImageOptimizer\OptimizerChain::class)->optimize($pathToImage, $pathToOptimizedImage);

Using the facade

use ImageOptimizer;

// the image will be replaced with an optimized version which should be smaller
ImageOptimizer::optimize($pathToImage);

// if you use a second parameter the package will not modify the original
ImageOptimizer::optimize($pathToImage, $pathToOptimizedImage);

You don't like facades you say? No problem! Just resolve a configured instance of Spatie\ImageOptimizer\OptimizerChain out of the container:

app(Spatie\ImageOptimizer\OptimizerChain::class)->optimize($pathToImage);

Using the middleware

All images that in requests to routes that use the optimizeImages-middleware will be optimized automatically.

Route::middleware('optimizeImages')->group(function () {
    // all images will be optimized automatically
    Route::post('upload-images', '[email protected]');
});

Adding your own optimizers

To learn how to create your own optimizer read the "Writing custom optimizers" section in the readme of the underlying spatie/image-optimizer package.

You can add the fully qualified classname of your optimizer as a key in the optimizers array in the config file.

Example conversions

Here are some example conversions that were made by the optimizer.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package (it's MIT-licensed), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

The idea of a middleware that optimizes all files in a request is taken from approached/laravel-image-optimizer.

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].