Convert base64 to image file in PHP

Today we will show you how to convert base64 to image file in PHP. In the previous article we learned how to convert an image to base64 encoded string using PHP.

Convert Base64 to image in PHP, Converting images into Base 64, php base64 encoded image from url, php decode base64 image and display, php convert base64 image to jpg, base64 image store in php, Convert base64 to image file and write To folder in PHP, How to convert a base64 image into a image file and save it in directory/folder.

Example to convert base64 to image file

Let’s assume that we’ve the following base64 image string.

Note: The given base64 image string is not a complete image string so use your base64 image string to execute the code. Check out the git source for the demo string.

Now try to generate an image file using PHP. The following code will help you to do it. Make sure you have an images directory with permission before executing the code.

index.php

After executing the index.php file we can get an image from base64 code and save it in the given path of the directory.

That’s it for today.
Thank you for reading. Happy Coding!

Demo & Source Code

Github Repository

You may also like...

2 Responses

  1. advert says:

    not working

Leave a Reply

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