Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imagecreatefrompng() from base64 code?

is there a way to create an image with imagecreatefrompng() with this base 64 PNG code in PHP?

like image 634
Jordan Jones Avatar asked Aug 15 '26 05:08

Jordan Jones


1 Answers

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.';
}
?>
like image 195
Juan David Rueda Quiroga Avatar answered Aug 18 '26 12:08

Juan David Rueda Quiroga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!