Skip to content

How to create an image from base64 format in Laravel 5.4

Last updated on February 17, 2018

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 
5 1 vote
Article Rating
Notify of

Most Voted
Newest Oldest
Inline Feedbacks
View all comments