PHP GD如何在一行上绘制文本 [英] PHP GD how to draw text over a line
本文介绍了PHP GD如何在一行上绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最终输出应类似于image(HELLO WORLD):
The final output should be like image(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, $x1, $y1, $txtcol, $font, $txt); // Drawing text over line at line's angle
当前输出如下:
有人可以告诉我我的代码有什么问题吗?
Can anybody tell whats the wrong with my code?
谢谢
推荐答案
好,一直在玩.尝试更换:
Ok, been playing around. Try replacing:
$texangle = (rad2deg(atan2($delta_y,$delta_x)) * 180 / M_PI)-360;
使用:
$texangle = (atan2($delta_y,$delta_x) * -180 / M_PI)-360;
输出您的值:
输出其他值:
这篇关于PHP GD如何在一行上绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文