动态生成词云? [英] Dynamically generating a word cloud?

查看:136
本文介绍了动态生成词云?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这就是我想在PHP中做的事情:

Ok well heres what I would like to do in PHP:

http://www.wordle.net/

我知道如何做所有的GD(写到画布),我的问题是实际上要跟踪不同大小的单词框并将它们正确放置在空白画布上的逻辑.如果有人知道一个好的网站,它的资源可以引导我朝正确的方向前进,那么我会永远爱你!

I know how to do all of the GD (writing to the canvas), my issue is the logic of actually keeping track of different sized word boxes and correctly placing them on a blank canvas. If anyone knows of a good site that has some resources that could lead me in the right direction I would love you forever!

推荐答案

好,您可以使用 imagettfbox (另请参见 http://ruquay.com/sandbox/imagettf/ )以获取您创建的标签文本的画布边界-给定字体,旋转度和大小(这显然取决于任何给定标签的出现次数).

Well you can use imagettfbox (see also http://ruquay.com/sandbox/imagettf/) to get the canvas boundaries of the tag text you created - given a font, rotation and size (which obviously depends on the number of occurrences of any given tag).

从那时起,您可以开始将标记词(随机??请参阅编辑)放置在云画布中,直到所有标记词都被放置为止.您只需要确保它们不重叠即可(即,您可以将像素坐标存储在数组中).

From that point you can start placing the tag words (randomly? - see edit) in the cloud canvas, until all of them are placed. You just have to make sure they don't overlap (ie you can store the pixel coordinates in a array).

您需要确保的另一件事是使图像画布足够大(或字体大小足够小)以容纳所有标签,因此您需要预先计算(再次使用imagettfbox)确切的像素每个单词的大小,并在所有单词都适合图像画布的大小之后,可以使用

One other thing that you need to make sure is to make the image canvas big enough (or the font size small enough) to accommodate all the tags, so you'll need to precalculate (again, using imagettfbox) the exact pixel size of each word and after you've reached a size where all the words can fit inside the image canvas you can start placing them using imagettftext.

编辑:您还可以学到很多东西(也许与开发人员联系),方法是查看信用,例如:

EDIT: You can also learn a lot (and maybe contact the developer) by taking a look at the credits, for example:

谢谢你,马丁·瓦滕伯格(Martin Wattenberg) 只是在扔东西的中心思想 屏幕直到适合为止.我举起我的 玻璃的哲学 可能最愚蠢的方法."

Thank you, Martin Wattenberg, for the central idea of just throwing stuff at the screen until it fits. I raise my glass to the philosophy of "the dumbest possible thing that works."

还有更多...

这篇关于动态生成词云?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆