25 Oct, 2017

Decode Base64 String to Image

25 Oct, 2017

Dear Reader, In this tutorial, let us we know about “base64 encoded image string conversion to its original image file format”.
For this, we are providing a base64 encoded string. And after executing this code you will get the actual image file.
In the same way, you can also get your actual image file from any encoded strings.

If you have strings with ‘data:image/png;base64’ this content then you have to use $data = str_replace(‘data:image/png;base64,’, ”, $data);
and if it is ‘data:image/jpeg;base64’ , then use $data = str_replace(‘data:image/jpeg;base64,’, ”, $data);
Hence make sure for jpeg type string , use jpeg str_replace code, and for other image format string use accordingly.

Create a folder images on your server like /var/www/html/WebPreparations/images
And Give permissions to this Folder in which you are going to save image files
/var/www/html/WebPreparations$ sudo chmod -R 777 images

And finally, you will get the image file as this image attached below.

«
»

Leave a comment:

Your email address will not be published. Required fields are marked *