PHP生成的图片如何保存

franzhong 2012-07-06 09:14:56

$targ_w = $targ_h = 150; //保存的图片的大小
$jpeg_quality = 90;
$src = '/image/abc.jpg';
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality);
ImageDestroy($dst_r);

现在图片可以正常显示了
1:但是如何自动保存在服务器abc123.jpg
2:要想再保存个50*50的缩略图怎么做abc123456.jpg
...全文
332 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
franzhong 2012-07-06
  • 打赏
  • 举报
回复
成功了,晕,名字错了,复贝的低级错误
franzhong 2012-07-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

1,
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )
第二个参数指定文件。

2,
bool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src……
[/Quote]
$myName1 = "123455.jpg";
imagejpeg($dst_r,$myName1,$jpeg_quality);

imagecopyresized($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
$myName1 = "1234.jpg";
imagejpeg($dst_r,$myName2,$jpeg_quality);
ImageDestroy($dst_r);
正确输出了123455.jpg, 1234.jpg未输出为何
无错误
qq120848369 2012-07-06
  • 打赏
  • 举报
回复
1,
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )
第二个参数指定文件。

2,
bool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
改一下昵称 2012-07-06
  • 打赏
  • 举报
回复
不输出,保存为文件,只需修改 imagejpeg()的第二个参数为文件名,那么自然也不需要 Header()声明输出流。
保存缩略图,参见 imagecopyresampled() 函数

21,886

社区成员

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

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