日期:2014-05-17  浏览次数:20510 次

PHP 图片上传,压缩,保存到服务器问题?
很简单上传服务器,从临时文件,'tmp_name'得到图片,
然后压缩。

$dstimage = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($dstimage,$srcimage,$dst_x, $dst_y , $src_x,$src_y ,$dst_w, $dst_h, $src_w,$src_h);
imagedestroy($srcimage);

查找了好久都没有找到如何,保存内存中的图片 $dstimage 的方法?

------解决方案--------------------

PHP code

/** 打开输出缓冲 **/
ob_start();

/** 输出图像 **/
imagepng($dstimage);

/** 获取缓冲区内容 **/
$img = ob_get_contents();

/** 清空输出缓冲 **/
ob_end_clean();

/** 然后把$img保存到文件就行了 **/

------解决方案--------------------
PHP code
// 保存的位置
$file = "/image/hello.png"
imagepng($dstimage, $file);