用PHP画一个有一定角度的矩形
我想用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--; }
}
}
我编写了这个函数来使用线条和循环来绘制它,但它并不像红色框那样正确出现。
有人可以告诉我我做错了什么吗?你甚至可以这样画吗?
I would like to draw a rectangle at an angle with PHP. I know that you can draw rectangles with PHP using imagefilledrectangle
but how to draw it an an angle.
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--; }
}
}
I wrote this function to draw it using lines and a loop but its not coming up right like the red box.
Can someone please tell me what am i doing wrong? And can you even draw it like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
imagepolygon()
或imagefilledpolygon()
使用 GD 绘制非矩形形状。您可能需要复习一些三角学知识来弄清楚如何定位点以获得直角。Use
imagepolygon()
orimagefilledpolygon()
to draw non-rectangular shapes using GD. You may need to review a bit of trigonometry to figure out how to position the points to get right-angle corners.我建议使用内置的 imagerotate 以及您的矩形使用
imagefilledrectangle
创建。下面是一个示例,创建一个旋转 30 度的 20x100 红色矩形:
I'd suggest using the built in imagerotate along with a rectangle you've created with
imagefilledrectangle
.Here's an example, creating a 20x100 red rectangle rotated 30 degrees: