how to create a base64encoded string from image re

2020-01-26 10:48发布

I have sent a base64 encoded string via AJAX to PHP and created an image resource with imagecreatefromstring - all is fine.

Now I want to get the base64 encoded string after resizing te image, but i CANT find a function to get the base64encoded string.

标签: php gdlib
1条回答
霸刀☆藐视天下
2楼-- · 2020-01-26 11:38

Taken from http://www.php.net/manual/en/book.image.php#93393

$image = imagecreatefromstring($file);

// start buffering
ob_start();
imagepng($image);
$contents =  ob_get_contents();
ob_end_clean();

echo "<img src='data:image/png;base64,".base64_encode($contents)."' />";

imagedestroy($image);
查看更多
登录 后发表回答