I'm looking for a good Tag Cloud Algorithm. I've googled around and I've only found one in psuedo code which i'm embarrassed to say can't understand, and another one that just plain sucks.

So, does anyone happen to have a good algorithm on hand. Right now I just used the most generic one possible for my script until I can find an intelligent one that keeps the tags balanced.

Here is the script I will be using it for.

http://upit.section31.us/?tags

Please Discuss.

    Let me try to clarify what my problem is. Lets say you have 100 common tags and the rest of the tags are under 10. You will have one huge Tag in the tagcloud and the rest will be super tiny. This is why i need a better algorithm that the most generic.

      The book PHP Hacks & Tricks has a very good code example for tag clouds similar to Flickr and most other sites that uses tags. It shows the most frequest tags in a text size larger than say a tag which is less frequent. IF I get some time this weekend, I'll copy it from the book and post it on here.

      Best,
      Cent

        What are you talking about? Clouds? Tags? Um... in English please?

          Here's an example of a tag cloud:

          Flickr

          best,
          cent

            I crossposted this at devshed and they were able to help me. In case anyone is interested here is the solution to what i was looking for.

            Demos:
            http://upit.section31.us/?tags
            http://image.azulinteractive.com/?tags
            Here is what the code looks like implemented.

            <?php
            define('TAG_MIN_FONT_EM', 1);
            define('TAG_MAX_FONT_EM', 3);
            
            function setFontEm($weight) {
            	$em = ($weight * (TAG_MAX_FONT_EM - TAG_MIN_FONT_EM)) + TAG_MIN_FONT_EM;
            
            return round($em, 2);
            }
            
            $tagCounts = array();
            $result = mysql_query("select distinct count(*) as tagCount from upit_tags group by tag order by tagCount asc");
            while ($row = mysql_fetch_assoc($result)) {
            	$tagCounts[] = $row['tagCount'];
            }
            mysql_free_result($result);
            
            $tagCounts = array_flip($tagCounts);
            $tagSizes = array();  $count = count($tagCounts);
            foreach ($tagCounts as $tagCount => $pos) {
            	$tagSizes[$tagCount] = setFontEm(($pos + 1) / $count)
            }
            unset($tagCounts);
            
            $sql = "select tag, count(*) as tagCount from upit_tags group by tag order by tag asc";
            $result = mysql_query($sql);
            
            ?>
            
            <div id="allTags">
            <? while ($row = mysql_fetch_assoc($result)) : ?>
            	<a href="?browse&amp;search=<?= $row['tag'] ?>" style="font-size: <?= $tagSizes[$row['tagCount']] ?>em;"><?= $row['tag'] ?></a> ... 
            <? endwhile; mysql_free_result($result); ?>
            </div>
            
              Write a Reply...