tags:

views:

354

answers:

2

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

http://www.wordle.net/

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!

A: 

Here is a link to a tutorial that uses jQuery and CSS to do most of the work - although you would need php to pass the values if they are stored in a database (As the tutorial assumes).

Robert DeBoer
Thats a basic word cloud, I'm talking about actually writing the text to a canvas like they do it.
Chad Scira
+2  A: 

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).

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:

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."

And much more...

Alix Axel