Here is my code:
$data = \'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl\'
. \'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr\'
. \'EX4IJT
This is the correct syntax for imagepng
:
imagepng($im, "/path/where/you/want/save/the/png.png");
According to the PHP manual:
bool imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] )
filename - The path to save the file to.
If not set or NULL, the raw image stream will be outputted directly.
Below code will be helpful:
$data = 'code in bytes'; // replace with an image string in bytes
$data = base64_decode($data); // decode an image
$im = imagecreatefromstring($data); // php function to create image from string
// condition check if valid conversion
if ($im !== false)
{
// saves an image to specific location
$resp = imagepng($im, $_SERVER['DOCUMENT_ROOT'].'folder_location/'.date('ymdhis').'.png');
// frees image from memory
imagedestroy($im);
}
else
{
// show if any error in bytes data for image
echo 'An error occurred.';
}
Please suggest if some other better way of doing !