Heatmap generation library using PHP and GD

While working on further development of my Helsinki public transport departures heatmap, I quickly noticed that heatmap.js, as good a library as it is, just can’t quite do all the things I needed it to do as fast as I’d like to get them done.

I decided to move some of the functionality on the server side, but didn’t find a PHP library that would allow me to do that, so I decided to write my own.

I initially tried PHP’s Imagick extension, but wasn’t happy with the performance. Doing a few test runs with GD instead looked more promising. After a few of hours of coding, I had a neat little package that would give me all the heatmaps I could ever want. I’ve uploaded the library to Github: https://github.com/xird/gd-heatmap, in case some else might find it useful.

If you have any feedback or feature requests, please leave a comment.

This entry was posted in IT. Bookmark the permalink.

8 Responses to Heatmap generation library using PHP and GD

  1. vizzy says:

    thank you! great script! exactly what i needed

    • amplifier says:

      No problem! When you’re done, leave a comment with a link to what you’ve made, if you like. It’s always fun to see how people use my stuff.

  2. mandy says:

    thanks for your excellent script!
    i just have one question, i notice that you have written several lines to “switch from white background to transparent”, but the image i get is still with white background. I do not know where i did wrong…

    • amplifier says:

      You’re generating a png, right? I.e. you have “‘format’ => ‘png’,” in your configuration? Jpegs don’t do transparency. I just tried the test script (test.php) included in the repository, and it generated white backgrounds by default. It started generating transparent backgrounds as soon as I switched the format parameter to “png”.

  3. 79xs says:

    How can I make it save to a file on the webserver instead of directly outputted to the screen?

    Thanks.

  4. 79xs says:

    Thanks for the update. It worked perfect.

    I run a game server that keeps stats in MySQL. It logs the X,Y,Z location of events (Deaths, Kills, Weapons, so on). Using a mix of your code, ImageMagick and Movie Studio, I was able to make this: https://www.youtube.com/watch?v=FXxsdPeum_0

Leave a Reply

Your email address will not be published. Required fields are marked *