Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a series of coordinates data which I plot onto an API-generated heatmap visualization using Google Maps API. The data changes daily, and I'd like to capture the heatmap and save it as a PNG or JPG image programmatically from within PHP so that a particular day's map can be recalled without regenerating the map and a number of maps could be sequenced together to show the changes animated over a given time period. I also need to be able to export a PDF report including a heatmap and this obviously would not work with a dynamic webpage frame.

Does anyone know:

  • of a way to save a Google-generated heatmap to a static PNG or JPG file, other than manually taking a screenshot and then cropping it to the bounds of the map? The solution needs to work in a GUI-less shared hosting environment as it will be deployed to many users with many different hosting configurations, the majority will not be skilled Linux experts or running a VPS; or

  • of an alternate tool for plotting coordinates onto a map and producing visualisations from this such as heatmaps, that can be saved into PNG or JPG files, from within PHP, and using only freely available PHP classes or default-installed PHP modules? (this is my prefered route if anyone has any tools in mind)

share|improve this question

1 Answer 1

It is possible to take screenshots programatically rather than manually. I do this on my charts and graphs site. The graphs are generated client side using JavaScript but I need thumbnail images created from them.

I'm using Java instead of PHP, but it should be similar.

  1. Install xvfb (X virtual frame buffer) so that Firefox can run on a headless server. Start it as a daemon configured as screen 99.
  2. Install a known version of firefox (eg /opt/firefox33/). I've found that selenium drivers are often not compatible with the newest release of firefox until the libraries get updated. Installing a known version gives me a lot more control over the upgrade process
  3. When you need a screenshot, have your code set the screen environment variable and start selenium with your installed firefox.

Here is an article about getting started with selenium from PHP that includes a screenshot example.

share|improve this answer
    
Hi Stephen, I've tried playing with Selenium but found it easier to just take the screenshots manually in the end. Ideally I'm looking for a solution that requires nothing more than PHP classes and modules normally installed so that it can be included in software that will be deployed by many different people without requiring a very prescribed hosting setup. The majority of end-users will likely be on shared hosting not VPS. –  richhallstoke Nov 14 at 12:43
    
I've just edited the question to make the scope/requirements more clear. Thank you for your suggestions. –  richhallstoke Nov 14 at 12:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.