Home > Backend Development > PHP Tutorial > PHP生成的图片怎么保存

PHP生成的图片怎么保存

WBOY
Release: 2016-06-13 13:24:25
Original
2423 people have browsed it

PHP生成的图片如何保存

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
    $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);

Copy after login

现在图片可以正常显示了
1:但是如何自动保存在服务器abc123.jpg
2:要想再保存个50*50的缩略图怎么做abc123456.jpg


------解决方案--------------------
不输出,保存为文件,只需修改 imagejpeg()的第二个参数为文件名,那么自然也不需要 Header()声明输出流。
保存缩略图,参见 imagecopyresampled() 函数
------解决方案--------------------
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 )
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template