繁体   English   中英

保存imagejpeg输出文件

[英]saving imagejpeg output the file

我在这里缺少什么吗? 如果我更改imagejpeg($thumb, $newImage); imagejpeg($thumb); 它回显了许多不可读的字符。 缩略图目录存在。

我的最终目的是复制较低质量的图像。

$filename = $imageDirectory . '/1.jpg';
$percent = 0.5;
$newImage = $imageDirectory . '/thumbs/1.jpeg';    
echo "image: <br>";
echo $filename;
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;    
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);    
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);    
// Output
imagejpeg($thumb, $newImage);

更新:我现在意识到第二个参数必须是具有新名称的图像位置。 所以...我已经重新定义了$ newImage。 路径很好...如果我手动将名为1.jpg的图像上传到该位置,则该路径中存在该图像。

如果要将图像输出到浏览器,则必须为响应添加正确的Content-Type标头:

header('Content-Type: image/jpeg');
imagejpeg($yourimage);

请检查文档中第一个示例以获取更多信息。 如果要在输出到浏览器之前降低质量,请检查第三个示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM