坐标系中的起点
我有以下 php 代码:
<?php
$image = imagecreatefrompng("captcha_background.png");
$imgcolor = imagecolorallocate($image, 0, 0, 0);
imagesetthickness($image, 2);
imageline($image, 0, 25, 40, 90, $imgcolor);
?>
“imageline”方法在我的图像上从坐标 0 (x) 25 (y) 到 40 (x) 90 (y) 绘制一条直线。
结果如下图:
我感到困惑的是使用坐标系时底部和顶部的反转在 PHP 中。 通常0(起点)位于左下角,但是当在“imageline”方法中分配坐标时,0(起点)位于左上角?
预期结果:
(图像为 300x100 像素)
有人可以解释为什么会发生这种情况吗?
I have the following php code:
<?php
$image = imagecreatefrompng("captcha_background.png");
$imgcolor = imagecolorallocate($image, 0, 0, 0);
imagesetthickness($image, 2);
imageline($image, 0, 25, 40, 90, $imgcolor);
?>
The method "imageline" draws a straight line on my image from the coordinates 0 (x) 25 (y) to 40 (x) 90 (y).
The result is the following image:
What I'm confused about is the reverse of the bottom and the top when using coordinate systems in php.
Normally 0 (The starting point) would be in the lower left corner, but when assigning coordinates in the method "imageline" the 0 (Starting point) is located in the upper left corner?
Expected result:
(The image is 300x100 pixels)
Could someone please explain why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是一个数学图表。开发中使用的典型坐标系(据我所知)是第一象限位于右下角。也就是说,0x0 位于左上角。这适用于所有具有宽度和高度的 html 元素(元素会下降,但不会上升)。
动机似乎是这样一个事实:在不知道图像的绝对高度的情况下,很难判断必须使用多少高度,因为您在任何给定时间可能都不知道图像的绝对高度,并且图像的绝对高度可能会经常变化。
This is not a mathematical graph. The typical coordinate system used in development (as far as I know) is to have the first quadrant at the lower right. That is, 0x0 is at the top left. This applies to all html elements that have widths and heights (the elements drop down, they do not fall up).
The motivation appears to be the fact that it's hard to tell how much height you have to work with without knowing the absolute height of the image, which you may not know at any given time, and which may change frequently.
这就是 GD 中坐标的定义方式,无需担心。
http://www.php.net/manual/en/function.imagedashedline.php :
That's how the coordinates are defined in GD, nothing to worry about.
http://www.php.net/manual/en/function.imagedashedline.php :
我相信这是 GD 图像库的标准,因为他们将自然原点定义为左上角。
I believe this is the standard for the GD image library as they define the natural origin as the top-left corner.