代码之家  ›  专栏  ›  技术社区  ›  DisgruntledGoat

将gd图像转换回二进制数据

  •  4
  • DisgruntledGoat  · 技术社区  · 15 年前

    我有一个gd图像资源创建自 imagecreatefromstring . 在一些图像操作之后,我想把它转换回二进制数据。我该怎么做?在手册中看不到任何功能…

    2 回复  |  直到 12 年前
        1
  •  6
  •   Annika Backstrom    15 年前

    使用 imagejpeg , imagepng ,或类似的。使用 output buffering 如果要将结果转储到字符串,而不是文件:

    ob_start();
    imagejpeg($im);
    $image_string = ob_get_contents();
    ob_end_flush();
    
        2
  •  1
  •   andrea    12 年前
    function image_data($gdimage)
    {
        ob_start();
        imagejpeg($gdimage);
        return(ob_get_clean());
    }