Here is my code:
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
I'd like to save the image generated this way to a directory. How do I do this?
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.
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