is there a way to create an image with imagecreatefrompng() with this base 64 PNG code in PHP?
Asked
Active
Viewed 3,214 times
3
-
4Yes, take a look at http://php.net/imagecreatefromstring and http://php.net/base64_decode (edit: actualy there is a sample on the first page) – Peter van der Wal Dec 13 '13 at 13:10
-
Yes, i was on that page earlier and i tried it, but it didn't work. – Jordan Jones Dec 13 '13 at 13:13
-
Did you strip off the `data:image/png;base64,`? – Peter van der Wal Dec 13 '13 at 13:14
-
Oh, i guess i didn't, sorry. – Jordan Jones Dec 13 '13 at 13:15
1 Answers
1
This works for me
<?php
$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.';
}
?>