Crazy Coders
Crazy Coders

Reputation: 133

How to add TinyPNG to Ckeditor & Elfinder?

i have a laravel 5 project.

i use Ckeditor and Elfinder to upload images in my posts.

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

Is there a way to do it ?

Upvotes: 0

Views: 353

Answers (1)

Asur
Asur

Reputation: 4017

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' => [
    ...
    Spatie\LaravelImageOptimizer\ImageOptimizerServiceProvider::class,
];

And:

// 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.

Upvotes: 1

Related Questions