imagecreatetruecolor()使我的图像质量下降 [英] imagecreatetruecolor() makes my image lose quality
问题描述
我正在使用以下脚本根据上传图片的人创建JPG。会发生的是,即使图像的宽度/高度完全相同,它仍然会失去质量以至于无法接受。
I'm using the script below to create an JPG based on people uploading an image. What happens is that even if an image is the exact same width/height it still loses quality so much that it's unacceptable.
$im = imagecreatefromjpeg($_FILES['cpicture']['tmp_name']);
$thumb=imagecreatetruecolor(507,307);
ImageCopyResampled($thumb,$im,0,0,0,0,$newwidth,$newheight,ImageSX($im),ImageSY($im));
ImagejpeG($thumb,"uploads/".$randomvalue.".jpg");
$imgurl="uploads/".$randomvalue.".jpg";
这些功能会降低质量吗?
Are these functions reducing the quality?
推荐答案
imagejpeg
第三个参数是要输出的图像的质量:
imagejpeg
's third parameter is the quality of the image to be output:
质量
是可选的,范围从0(最差质量,较小文件)到100(最佳质量,最大文件)。默认值是默认的IJG质量值(约75)。
quality
is optional, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default is the default IJG quality value (about 75).
尝试将代码的相关行更改为:
Try changing the relevant line of your code to:
ImagejpeG($thumb,"uploads/".$randomvalue.".jpg", 100);
这篇关于imagecreatetruecolor()使我的图像质量下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!