微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP GD如何通过一行绘制文本

最终输出应该像图像(HELLO WORLD):

这是我在做什么: –

$im = imagecreate(400,400); 

$txtcol = imagecolorallocate($im,0xFF,0x00,0x00);

$size = 20;

$txt = 'DUMMY TEXT';

$font = './font/Capriola-Regular.ttf';

/*two points for base line*/

$x1 = 50; $x2 = 300; 

$y1 = 150; $y2 = 170;

/*bof finding line angle*/

$delta_x = $x2-$x1;

$delta_y = $y2-$y1;

$texangle = (rad2deg(atan2($delta_y,$delta_x)) * 180 / M_PI)-360;

/*eof finding the line angle*/


imageline($im,$x1,$y1,$x2,$y2,$txtcol); //Drawing line

imagettftext($im,$size,$texangle,$txtcol,$font,$txt); // Drawing text over line at line's angle

目前的输出如下:

任何人都可以告诉我的代码有什么问题吗?

谢谢

好的,一直在玩.尝试更换:
$texangle = (rad2deg(atan2($delta_y,$delta_x)) * 180 / M_PI)-360;

附:

$texangle = (atan2($delta_y,$delta_x) * -180 / M_PI)-360;

输出您的值:

输出与其他值:

原文地址:https://www.jb51.cc/php/134099.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐