我正在使用一个解决方案,将图像文件组装成zip并流式传输到浏览器/Flex应用程序。(ZipStream由Paul Duncan制作,http://pablotron.org/software/zipstream-php/)。
只是加载图像文件并压缩它们可以正常工作。以下是压缩文件的核心代码:
// Reading the file and converting to string data
$stringdata = file_get_contents($imagefile);
// Compressing the string data
$zdata = gzdeflate($stringdata );
我的问题是,我想在压缩图片之前使用GD处理图片。因此,我需要一种将图像数据(imagecreatefrompng)转换为字符串数据格式的解决方案:
// Reading the file as GD image data
$imagedata = imagecreatefrompng($imagefile);
// Do some GD processing: Adding watermarks etc. No problem here...
// HOW TO DO THIS???
// convert the $imagedata to $stringdata - PROBLEM!
// Compressing the string data
$zdata = gzdeflate($stringdata );
有什么线索吗?
ob_start
,它失败了。我发现下面 M.i.X 的答案是更好的解决方案。 - supersan