Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将imagegif()转换为变量?_Php_Image_Php Gd - Fatal编程技术网

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();