Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 443
Vineet Avatar asked Sep 01 '16 06:09

Vineet


1 Answers

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

like image 73
Rithy Sam Avatar answered Oct 02 '22 23:10

Rithy Sam