Quality must range from 0 to 100 - Intervention Laravel 5.x
Asked Answered
F

4

7

I'm using intervention/image 2.3. When I try to upload an image I got the following error :

InvalidArgumentException in AbstractEncoder.php line 212

Quality must range from 0 to 100

Below is my code for that :

$file = Input::file('image');
$filename = time() . '.' . $file->getClientOriginalExtension();
Image::make($file)->resize(50, 50)->save(storage_path() . DIRECTORY_SEPARATOR . 'uploads', $filename);

Any single guidance will help me alot. According to this URL I tried out to pass second optional parameter ie quality but didn't work. I tried even

Image::make($file)->resize(50, 50)->save(storage_path() . DIRECTORY_SEPARATOR . 'uploads'. $filename, 50);
Fauve answered 1/9, 2016 at 6:33 Comment(1)
Oh! I got the error. There was comma in my code. Image::make($file)->resize(50, 50)->save(storage_path() . DIRECTORY_SEPARATOR . 'uploads', $filename); before $filename. It should be .Fauve
P
2

I have faced this problem, and I solved it by the following code:

$file = $request->file('img_profile');
$file_name = date('Ymd-his').'.png';
$destinationPath = 'uploads/images/';
$new_img = Image::make($file->getRealPath())->resize(400, 300);

// save file with medium quality
$new_img->save($destinationPath . $file_name, 80);

Check http://image.intervention.io/api/save for more...

Paillette answered 26/1, 2020 at 16:8 Comment(0)
M
0

save() method's 1st argument should be path+name, 2nd quality (0-100), you used "," between path and $filename instead of . Do something like ->save('your/path/'.$filename); or ->save('your/path/'.$filename, 80);

Mast answered 25/2, 2020 at 16:17 Comment(0)
S
0

I have faced this problem, use the save() like this

$image = $request->file('img_src');
$filename = time().'.'.$image->getClientOriginalExtension();
$image_resize = Image::make($image->getRealPath());
$image_resize->fit(250);
$image_resize->save(public_path('/imgs/'.$filename));
Stockyard answered 28/6, 2021 at 14:16 Comment(0)
S
0

The problem is that you are passing file name in place of quality parameter.

Possibly you are rewriting basic from $file->move() method? Just replace comma with one more DIRECTORY_SEPARATOR:

Image::make($file)->resize(50, 50)->save(storage_path() . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $filename);
Siffre answered 3/2, 2023 at 0:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.