Answer the question
In order to leave comments, you need to log in
laravel image optimization (Image-Optimizer)?
I want to tie to the site image compression when loading.
I read and decided to use Image-Optimizer .
Installed. In controller:
use Spatie\LaravelImageOptimizer\Facades\ImageOptimizer;
public function store(Request $request)
{
$settings = $this->settings;
$this->reIndex();
if ($request->hasfile('filename')) {
$file = $request->file('filename');
$name=time().$file->getClientOriginalName();
$path = $file->move(public_path().'/img/', $name);
ImageOptimizer::optimize($path);
}
$img= new \App\Img;
$img->filename=$name;
$img->save();
return redirect('news')->with('success', 'Новость успешно добавлена!');
}
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;
Answer the question
In order to leave comments, you need to log in
You must have the necessary extensions for this lib to work, it itself detects (if you do not specify it) a suitable one and compresses
https://github.com/spatie/image-optimizer#optimiza...
For example, jpegoptim should be set for Jpegoptim (in C seems to be written), I also use it
And so - your pipeline is wasted
Try https://github.com/OrlovEvgeny/TinyJPG
this is a watcher daemon that subscribes to the fs event of the image directory and if a new image appears in the directory, it compresses it. Compressing via php is a little expensive.
I'll share my experience of compressing pictures... At first, I had to manually recompress all the pictures through Photoshop. By the way, the most free option (except for the cost of a license for Photoshop). But this process takes a lot of time if there are more than 10-20 pictures on the site. After all, each picture must be manually processed, and then uploaded to the site again. Such a tedious process... Now I use this service - https://optipic.io/ Saves a lot of time) Works by itself - automatically - only 1 time it needs to be connected to the site. Google is happy
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question