我将开始使用GD库在PHP中构建地图生成器.我使用lib生成了一些图像,但它们没有很好的质量.我只想知道有一些方法可以提高图像的质量.
生成的图像是:
我的代码是:
<?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, …
Run Code Online (Sandbox Code Playgroud) 我想用PHP绘制一个矩形角度.我知道你可以使用PHP绘制矩形imagefilledrectangle
但是如何绘制一个角度.
public function drawshelf($x1, $y1, $x2, $y2, $width, $angle = 'false'){
imagesetthickness ( $this->canvas, 1 );
for ($i=0; $i < $width; $i++){ //HORIZONTAL
imageline( $this->canvas, $x1, $y1, $x2, $y2, $this->color );
$y1++; $y2++;
if( $angle == 'true' ){ $x1--; $x2--; }
}
}
Run Code Online (Sandbox Code Playgroud)
我写了这个函数来使用线条和循环绘制它,但它不像红色框那样正确.
有人可以告诉我,我做错了什么?你甚至可以这样绘制它吗?
我刚刚编写了这段代码来生成图像
<?php
$canvas = imagecreatetruecolor(800, 350);
$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);
imagefill($canvas, 0, 0, $white); // BACKGROUND
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);
// Output and free from memory …
Run Code Online (Sandbox Code Playgroud)