I am using a simple image upload php code but the image quality goes down for 100x100 50x50. How can I increase image quality?
我使用简单的图像上传PHP代码,但图像质量下降100x100 50x50。如何提高图像质量?
I want to a use good quality of photos when they get uploaded.
我想在上传时使用高质量的照片。
if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src= imagecreatefrompng($uploadedfile);
imagealphablending($src, false);
imagesavealpha($src, true);
imagealphablending($src, false);
imagesavealpha($src, true);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
echo $scr;
list($width,$height)=getimagesize($uploadedfile);
if($width>75)
{
$newwidth=50;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
$newwidth1=100;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$mainfilename = $username.".".$ext;
$filename = "pics/50/". $username.".".$ext;
$filename1 = "pics/100/". $username.".".$ext;
imagejpeg($tmp,$filename,50);
imagejpeg($tmp1,$filename1,100);
Can anybody help me to create 4 size thumbnail photos using one large photo but with good quality?
任何人都可以帮我用一张大照片制作4张尺寸的缩略图,但质量很好吗?
2 个解决方案
#1
0
The third parameter of imagejpeg()
is the image quality (not the size as your code seems to imply).
imagejpeg()的第三个参数是图像质量(不是您的代码似乎暗示的大小)。
Simply set this to 100 for maximum quality.
只需将其设置为100即可获得最高质量。
#2
0
From the imagejpeg documentation
来自imagejpeg文档
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )
So to get the highest quality of your image you need to set the quality to 100
因此,要获得最高质量的图像,您需要将质量设置为100
//0 = lowest, 100 = highest. ~75 = default
imagejpeg($tmp1,$filename1,100);
#1
0
The third parameter of imagejpeg()
is the image quality (not the size as your code seems to imply).
imagejpeg()的第三个参数是图像质量(不是您的代码似乎暗示的大小)。
Simply set this to 100 for maximum quality.
只需将其设置为100即可获得最高质量。
#2
0
From the imagejpeg documentation
来自imagejpeg文档
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )
So to get the highest quality of your image you need to set the quality to 100
因此,要获得最高质量的图像,您需要将质量设置为100
//0 = lowest, 100 = highest. ~75 = default
imagejpeg($tmp1,$filename1,100);