Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically generating a word cloud?

Tags:

php

math

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!

like image 735
Chad Scira Avatar asked Aug 20 '09 17:08

Chad Scira


People also ask

Does MS word have a word cloud generator?

Generate word cloud visualizations of web pages, text files, or other arbitary text inputs Useful for a quick breakdown/summary of what the page is talking about, or at least the buzzwords for a document. To begin using the word cloud software, just copy and paste the text in and press the run button.

Does PowerPoint have a word cloud generator?

Generating your word cloud To access the add-in in PowerPoint, head to Insert > My Add-ins > See All. From this menu, select Pro Word Cloud. Once you open it, you're going to get a sidebar on the right-hand side of the page where you can control a few options about how your word cloud is going to look.

What is an interactive word cloud?

interactive word clouds. Capture people's thoughts and ideas in a beautiful word collage. Loved by presenters and. participants alike, the most popular answers grow dynamically as people submit them.


1 Answers

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

like image 50
Alix Axel Avatar answered Oct 25 '22 06:10

Alix Axel