I am trying to take a Base64 encoded image from the database and save it to a file. For whatever reason, when I try using imagecreatefromstring & imagepng the image is completely black. I have tried many different approaches, but I still end up with a black box. Below is my best attempt to get it to work. Any ideas? Thank you so much in advance!
$thefile = base64_decode($strImage);
$img = imagecreatefromstring($thefile);
if($img !== false)
{
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
}
This should be above, but the formatting did not look right....
$strImage='iVBORw0KGgoAAAANSUhEUgAAA4QAAAD6CAYAAAD5jokXAAAMrUlEQVR4nO3dPahkZxkH8P+CkiqlaKGojcHCr9gEBBsbu5QiSRXBTksRsUijwcI0IorBD4gGGwvxC4soKLEQImiMRgMmMYmRGDbZbLJ7d++9Zy3OPdzZ2bv3zuzMnOd8/H4wxe4O8z4zmWL+ed73fRIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABG4ukkzQmPgyQXkjxcVxoAAAC78kba8HeY5OrRY//oz4vhcL+qQAAAAHanOeXfPpe2U9gFw2d6qQgAAIBeXFvhOa9FtxAAAGByTusQLlvsFr68m3IAAADoyyodwkW6hQAAABOxTodwUdctPNxiLQAAAPRo3Q7hor0cdwtf3U45AAAA9GWTQJgkP48tpAAAAKN0q1tGl9lCCgAAMDKbdggXLW4h/d0WXxcAAIAd2GYgTI63kF5L8uaWXxsAAIAt2taW0WWHR6+9t6PXBwAAYEPb7hAuEgoBAAAGbJeBMBEKAQAABmtXW0YXCYUAAAADtOsOYUcoBAAAGJi+AmEiFAIAAAxKn4EwEQoBAAAGo48zhMu6UHi5YG0AAACO9N0h7HSh8N9F6wMAAMxeVSBM2kDYJPl4YQ0AAACzVRkIf5DjUAgAAEDPKgNhkryWNhAeFtcBAAAwO0Pozu2lreOguhAAAIA5qe4QdvbThsKr1YUAAADMxVACYdJ2CJskF6sLAQAAmIMhBcLEJTMAAAC9GVogvJw2EL5RXQgAAMDUDS0QJrqEAAAAO3d3hhm8Xk9b1151IQAAAFPWJLlUXcQJDjPMsAoAADBoz6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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAbfo/R04U3Pjl9j8AAAAASUVORK5CYII=';
Call imagesavealpha() before your imagepng()
imagesavealpha($img, true);
imagepng($img);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With