【发布时间】:2020-08-14 22:06:06
【问题描述】:
此代码从数组中随机生成图像。它工作正常,但图像被严重压缩。有没有办法保持质量?
$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);
【问题讨论】:
-
图像质量的默认值为 75。要将其更改为 100(最佳质量),您需要将
imagejpeg($image);更改为imagejpeg($image, NULL, 100);
标签: php image compression