Current Release 0.5.0 Beta (download - .zip - 16k - CC 3.0 Attribution license)

What Is A Heatmap?

Thanks to siewlian for our underlying photo

A heatmap is a way of visually overlaying hostspots of incidence/concentration on a grid. The hotspots can represent a clickstream (I set up a little AJAX script to record every time I clicked on the photo above and then rendered the data of where I clicked as a heatmap), or it could be the incidence of robberies or concentrations of zombies on a map.

Long story short, I got curious about heatmaps last year, but all the solutions I'd found were not in PHP, used the ImageMagick library, had a complex API, produced a heatmap I thought sucked, or multiple elements from that list. Eventually, because it produced the kind of map I wanted and could work simply, I first ported "The Definitive Heatmap" from Ruby to PHP.

I still didn't like the fact that it used ImageMagick (because many people on shared servers might not have access to ImageMagick), plus it executed the ImageMagick commands to the shell, which is not as secure as I'd like. So I re-wrote the whole thing to use PHP's built in graphics library, GD. That came with its own set of pitfalls, most notably being that GD has no Multiply blend mode. I had to create a GD Multiply blend in PHP from scratch. For those of you who arrived here specifically because you were Googling for a PHP script to do a Multiply blend with GD, you'll find that code in the overlayDot() method of the class.

I added a few functional modifications, did about an hour of testing to make sure it worked, wrote up the README, and packed it up.

The download package contains the class file, a README with instructions on how to use it, and a graphics folder with a color strip and dot image needed to create the overlay images. You'll need a basic knowledge of PHP and arrays to install this and make it work with the sample code.

Enjoy the class and if you have any questions, comments, bug reports, feature requests, or just plain praise, please post your thoughts below.

Current Release 0.5.0 Beta (download - .zip - 16k - CC 3.0 Attribution license)

PHP Programming Innovation award nominee
September 2011


Comments are closed.

Get an angel for your site An Angel Watches Over This Site