Issue
So, I'm using the following code:
$currentIMG = imagecreatefromstring(base64_decode($img));
Where $img is a base64 string. When I echo base64_decode($img) it shows me a string (as it should), but when I use imagecreatefromstring() it shows the following error:
Fatal error: Uncaught Error: Object of class GdImage could not be converted to string
I can guarantee that the base64 string is not broken because it works on online base64 to image converters, so I can't figure out what's the problem.
Thanks in advance!
Code:
function base64toImage($img) {
$currentIMG = imagecreatefromstring(base64_decode($img));
echo $currentIMG;
}
Solution
Instead of doing:
echo $currentIMG;
Which tries to print a GDImage
as if it is a string, use something like:
Header('Content-type: image/png');
imagepng($currentIMG);
Answered By - Raxi
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.