How to create an image from base64 format in Laravel 5.4

I will show you, how is easy it is to convert base64 format image to image. All you have to extract the base64 image data from that string, decode it and then you can save it to disk.

Here is the function, which will save a base64 image to disk.

public function createImageFromBase64(Request $request){ 
   $file_data = $request->input('company_logo'); 
   $file_name = 'image_'.time().'.png'; //generating unique file name; 
   @list($type, $file_data) = explode(';', $file_data);
   @list(, $file_data) = explode(',', $file_data); 
   if($file_data!=""){ // storing image in storage/app/public Folder 
          \Storage::disk('public')->put($file_name,base64_decode($file_data)); 
    } 
}

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

DMCA.com Protection Status