我已经通过 AJAX 向 PHP 发送了一个 base64 编码的字符串,并使用 imagecreatefromstring
创建了一个图像资源 - 一切都很好。
现在我想在调整图像大小后获取 base64 编码的字符串,但我找不到一个函数来获取 base64 编码的字符串。
最佳答案
取自 http://www.php.net/manual/en/book.image.php#93393
$image = imagecreatefromstring($file);
// start buffering
ob_start();
imagepng($image);
$contents = ob_get_clean();
echo "<img src='data:image/png;base64,".base64_encode($contents)."' />";
imagedestroy($image);
关于php - 如何从图像资源创建 base64 编码的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8502610/