我将使用GD库在PHP中开始构建地图生成器。我已经使用该库生成了一些图片,但它们的质量不够好。我只想知道是否有方法可以提高图片的质量。
生成的图片是:
我编写的代码是:
生成的图片是:
![the img](https://istack.dev59.com/E0Hju.webp)
<?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');
)可能是更好的格式。 - gen_Eric