[英]PHP jpeg image created from file is low quality
This code randomly generates an image from an array.此代码从数组中随机生成图像。 It works fine, but the image is compressed heavily.
它工作正常,但图像被严重压缩。 Is there a way to keep the quality?
有没有办法保持质量?
$img = array('1.jpg', '2.jpg', '3.jpg' ); // Adds images into an array
$i = rand(0, count($img)-1); // Generates a random number (max being the last elements index from the array)
$chosenimg = "$img[$i]"; // Sets the variable $chosenimg to equal to whatever the random image was
$image = imagecreatefromjpeg($chosenimg);
imagealphablending($image, false);
imagesavealpha($image, true);
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
Checking the official documentation :检查官方文档:
bool imagejpeg ( resource $image [, mixed $to [, int $quality ]] )
so you have to change imagejpeg($image);
所以你必须改变
imagejpeg($image);
with imagejpeg($image, null, 100);
与
imagejpeg($image, null, 100);
to get the best quality.以获得最好的质量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.