ihprince's avatar

How to resize image before upload in laravel?

I want to resize image beofre upload it into database. I store image in this way

$image = $request->image;

  if ($image) {
     $image_name = hexdec(uniqid());
       $ext      = strtolower($image->getClientOriginalExtension());
       $image_full_name = $image_name . '.' . $ext;
       $upload_path     = 'foods/';
       $upload_path1    = 'images/foods/';
       $image_url       = $upload_path . $image_full_name;
       $success         = $image->move($upload_path1, $image_full_name);

        }

Now, I want to resize image before uploading it. I try to use intervation package, I try this

if ($image) {
     $image_name = hexdec(uniqid());
       $ext      = strtolower($image->getClientOriginalExtension());
       $image_full_name = $image_name . '.' . $ext;
       $upload_path     = 'foods/';
       $upload_path1    = 'images/foods/';
       $image_url       = $upload_path . $image_full_name;
       $img = Image::make($image)->resize(300, 200);
       $img->save($upload_path1, 60, $image_full_name);

        }

and I got this error

 "Encoding format (1691942233153059.jpg) is not supported."

What is the best way to resize image before upload and also set image with unique name?

0 likes
6 replies
ihprince's avatar

It holds the requested image which comes from input file .

 $image = $request->image;
ihprince's avatar

I already tried this, It gives this error

 " Quality must range from 0 to 100. "
MichalOravec's avatar
Level 75

There is a dot and not comma between $upload_path1 and $image_full_name

$img->save($upload_path1.$image_full_name, 60);
1 like

Please or to participate in this conversation.