我將開始使用GD庫在PHP中構建一個地圖生成器。我使用lib生成了一些圖像,但它們質量不好。我只是想知道,有什麼方法可以提高圖像的質量。提高PHP GD生成圖像的質量
所生成的圖像是:
,我提出的代碼是:
<?php
$canvas = imagecreate(800, 350);
imagecolorallocate($canvas, 255, 255, 255);
$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);
imagestring($canvas, 20, 290, 25, "Quality is not the best :(", $green);
function drawlinebox($x1, $y1, $x2, $y2, $height, $color){
global $canvas;
imagesetthickness ($canvas, 1);
for ($i=1; $i < $height; $i++){
imageline($canvas, $x1, $y1, $x2, $y2, $color);
$y1++; $y2++;
}
}
drawlinebox(20, 20, 780, 300, 30, $green);
drawlinebox(20, 300, 780, 20, 30, $pink);
header('Content-Type: image/jpeg');
imagejpeg($canvas);
imagedestroy($canvas);
?>
嘗試使用'imagepng'而不是'imagejpeg'。 PNG('header('Content-Type:image/png');')可能是一個更好的格式。 –
您是否嘗試過抗混疊功能? – kaiser