2011-10-17 104 views
5

我可以base64对我创建的图像进行编码,而无需先将其保存到磁盘上?据我所知,base64_encode()只接受字符串,我没有找到一种方法来检索图像源对象作为字符串没有先保存,并加载它file_get_contents()base64在不保存的情况下对图像进行编码

+0

我建议不要使用'file_get_contents()',因为它有时候会非常非常慢。使用卷曲。 – switz

回答

9

GD不提供一种方法来返回输出图像作为文本,但你可以用输出缓冲功能来伪造:

ob_start(); 
imagejpeg($handle); // no second parameter, will do output instead of writing to file 
$img = ob_get_clean(); 

echo base64_encode($img); 
相关问题