PHP 图片上传,压缩,保存到服务器问题?

熊猫哥哥 2012-04-26 11:13:24
很简单上传服务器,从临时文件,'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 的方法?
...全文
237 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
熊猫哥哥 2012-04-28
  • 打赏
  • 举报
回复
搞定了。 不过BMP好像GD库木有办法啊。
改一下昵称 2012-04-27
  • 打赏
  • 举报
回复
// 保存的位置
$file = "/image/hello.png"
imagepng($dstimage, $file);


说明

bool imagepng ( resource $image [, string $filename ] )
imagepng() 将 GD 图像流(image)以 PNG 格式输出到标准输出(通常为浏览器),或者如果用 filename 给出了文件名则将其输出到该文件。
熊猫哥哥 2012-04-26
  • 打赏
  • 举报
回复
没看懂,能具体点吗?
我就这个 $dstimage
最好保存怎么弄?
hengyu654 2012-04-26
  • 打赏
  • 举报
回复


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

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

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

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

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

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧