Php 如何将imagegif()转换为变量?
我正在尝试将Php 如何将imagegif()转换为变量?,php,image,php-gd,Php,Image,Php Gd,我正在尝试将imagegif()的内容获取到一个变量,或者将gif保存到一个变量中 我想我可以做一个临时文件和file\u get\u contents(),但我正在寻找一个更简单的方法。我不使用Imagemagick,我使用的是GD。您应该能够使用。这只是手册中使用上述输出缓冲区的一个简化示例: function makeGif() { # Start capturing the content ob_start(); # -------
imagegif()
的内容获取到一个变量,或者将gif保存到一个变量中
我想我可以做一个临时文件和
file\u get\u contents()
,但我正在寻找一个更简单的方法。我不使用Imagemagick,我使用的是GD。您应该能够使用。这只是手册中使用上述输出缓冲区的一个简化示例:
function makeGif()
{
# Start capturing the content
ob_start();
# -------- Just do your image script starting here --------- #
$im = imagecreatetruecolor(100, 100);
imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);
imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);
imagegif($im);
imagedestroy($im);
# -------- stopping your image here -------- #
# This assigns the content of the output
$img = ob_get_contents();
# Stop capturing the output
ob_end_clean();
# Send back the content
return $img;
}
# $image should now contain the gif data
$image = makeGif();