我有一个数组中的单词列表,我可以使用imagettftext写入PNG。PHP:imagettftext&imagettfbbox - 单词碰撞检测
imagettfbbox正被用来确定下一个单词应该去的地方。
我想检查当前的字我试图写的图像将与之前的词,已被写入重叠(我假设imagettfbbox是要走的路?)
以下是我假设的代码是这样(我不能让我围绕如何做到这一点的头!):
If the current word will overlap with previous word
Position current word further down an ever increasing spiral until it doesn't collide
目前我的代码,会写的所有字的图像不重叠,但没有任何角度(这是我希望它在将来处理的事情 - 没有文字碰撞)
$handle = ImageCreate(1000, 500) or die ("Cannot Create image");
//Background Colour
$bg_color = ImageColorAllocate($handle, 0, 150, 255);
$txt_color = ImageColorAllocate($handle, 0, 0, 0);
// First we create our bounding box for the first text
$bbox = imagettfbbox($fontsize, $angle, $font, $word);
// Set X Coord
$x = ($bbox[2] - $bbox[0]);
// Set Y Coord
$y += ($bbox[7] - $bbox[1]);
// Write word to image
ImageTTFText($image, $fontsize, $angle, $x, $y, $txt_color, $font, $word);
这个代码在你看的时候是非常静态的,并且不会将单词限制在图像的大小(也是我想要的)。
任何帮助将不胜感激,我一直坚持在这个过去两周,并真的想继续前进!
我也尝试过使用这种方法,它似乎仍然不适合我!你能否让我看看你的程序做了些什么?谢谢 – Jon
你知道吗,我只是注意到在那段代码中,'$ dx'和'$ dy'从来没有使用过......它们实际上是从'$ x'和'$ y'中减去的,但是那行被注释掉了,所以我想知道我是否有这方面的问题。这是我完整的方法;它使用了很多类变量,但它们应该是不言自明的,因为它们应该满足您的需求。我想你可能会对每行写完后行间距设置增加的行感兴趣。它应该为你评论得很好。 http://pastebin.com/HrwNn875 – Demonslay335