Yalın Semer Yalın Semer - 6 months ago 47
PHP Question

How to add TinyPNG to Ckeditor & Elfinder?

i have a

laravel 5

i use
to upload images in my posts.

Normally , i use
php api to optimize my other images. But i can't integrate
api to

Is there a way to do it ?

Answer Source

I would recommend you to install laravel-image-optimizer by Spatie, basically it sets up a middleware which detects when the request contains an image and it passes the correct image optimizers you have installed in your system automatically.

To install it run:

composer require spatie/laravel-image-optimizer

And add to your config file app.php:

// config/app.php
'providers' => [


// config/app.php
'aliases' => [
    'ImageOptimizer' => Spatie\LaravelImageOptimizer\ImageOptimizerFacade::class,

To use it wrap the upload endpoint with the middleware:

Route::middleware('optimizeImages')->group(function () {
    // all images will be optimized automatically
    Route::post('upload-images', 'UploadController@index);

As mentioned in the documentation the supported optimizers by default are:

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

  • JpegOptim
  • Optipng
  • Pngquant 2
  • SVGO
  • Gifsicle

If you want, by all means, to use your optimizer, this package has you covered, just follow this section of the documentation.

Hope this helps you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download