galaners's avatar

Best way to optimize file images during upload in Laravel

I've a form with a multiple file input that accept only images (of course I've some validator for the request, etc.). But I'm looking for the best way to optimize the files during the upload method so they doesn't :

private function upload_files($file, $table_id) {
        $myImagesTable = new MyImagesTable;
        $myImagesTable-> table_id = $table_id;
        $myImagesTable->name = $file->store('images', 'public'); // During this process I need to optimize the image
        if(!$myImagesTable->save()) {
            return back()->with('error', __('An error occurred... Please try again later'));   
        }
    }

I've check some of the following solutions:

I don't care that the images have the best quiality (even tho I do care that the optimization process doesn't affect the quality THAT much).

I really want to hear your opinion before making a chooice. Thanks

0 likes
6 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

The spatie package looks pretty good. But I believe intervention will be fine.

I suggest you try (experiment) with the packages, you can always uninstall the one you don't use.

2 likes
aschmelyun's avatar

@jlrdw +1 recommendation for Intervention. Tons of fine-grained control and great to work with from a dev perspective.

1 like
Snapey's avatar

can you explain your question further

also put three backticks ``` on their own line before and after the code

1 like
galaners's avatar

@Snapey Ok, I corrected the code and I don't know how I can explain further, I'm just asking the opinion of another developers about the best method to optimize images during the upload

Snapey's avatar

@galaners

But I'm looking for the best way to optimize the files during the upload method so they doesn't :

so they doesn't what?

Please or to participate in this conversation.