从作为图像的变量中获取文件内容

时间:2014-05-11 00:20:40

标签: php mysql file-get-contents

我应该使用什么函数从变量获取文件内容(jpg):

 $filename = 'temporary.jpg';
 $percent = 2.5;
 list($width, $height) = getimagesize($filename);
 $newwidth = $width * $percent;
 $newheight = $height * $percent;
 $thumb = imagecreatetruecolor($newwidth, $newheight);
 $source = imagecreatefromjpeg($filename);    
 imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

更具体地说,我在谈论$ thumb变量,即图像。 我想这样做来解压缩这些数据,然后发送到DB

1 个答案:

答案 0 :(得分:1)

默认情况下,像imagejpeg()这样的图像存储功能会将数据输出到浏览器。您可以将其捕获并保存到变量中,如下所示:

ob_start();
imagejpeg($thumb);
$thumbData = ob_get_clean();

然后将其作为任何其他(二进制)字符串插入数据库。