Posted by Arjun on Friday 7th July 2017

How to create an image from base64 format in Laravel 5.4

Laravel 5.x Laravel 5.4 base64 to image

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