2

I want to compress the uploaded image and store the base64 of the image in the database. Every time I google the question I always gets the idea to use the image stored in a certain path. I'm using intervention/image package

I have tried this code

$img = Image::make($request->photo)->resize(300, 200);
//get the extension
$type = $request->file('photo')->getClientOriginalExtension();
//convert it into the base64.
$base64 = 'data:image/' . $type . ';base64,' . base64_encode(file_get_contents($img));

I want to store the photo in the database after compressing and converting into the base64 format. Error that I got

zlatan
  • 3,346
  • 2
  • 17
  • 35

1 Answers1

2

You need not write any compression or conversion code. Try adding encode('data-url')

I hope it works.

$img = Image::make($request->photo)->resize(300, 200)->encode('data-url');
Nikkon
  • 61
  • 5