In this tutorial, i will show you how to convert base64 string to image and write it into folder in PHP. i will write simple code for save base64 encoded image to file using php and you can save it png, jpg as you want.
Many times you need to require to convert base64 string to image and save it to folder. If you are work with an API creation then it is very simple to work with base64 string and you need to convert base64 encoded string into image.
Here in this example i write function generateImage() from base64 string. you can simply follow bellow example:
public function generateImage($img)
$folderPath = "images/";
$image_parts = explode(";base64,", $img);
$image_type_aux = explode("image/", $image_parts);
$image_type = $image_type_aux;
$image_base64 = base64_decode($image_parts);
$file = $folderPath . uniqid() . '.png';
I hope it can help you....
Do you like below Tutorials ?
- How to create PDF file in Laravel 5.6?
- PHP Laravel 5.6 get current user details
- How to get last query log in Laravel 5.6?
- PHP - How to remove double quotes from json array keys?
- Laravel 5.6 - Excel and csv import export using maatwebsite example
- VueJS - How to set maxlength for textarea?
- Laravel - Get last inserted id using save(), create() and insertGetId()
- Laravel - How to handle "No query results for model" Error