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);
Community
  • 1
  • 1
Vineet
  • 4,525
  • 3
  • 23
  • 42
  • 3
    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 `.` – Vineet Sep 01 '16 at 06:39

4 Answers4

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

Rithy Sam
  • 41
  • 4
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);

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));
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);
Mike
  • 378
  • 1
  • 8