0

I have a php file that can generate html or js files that would draw a graph in the browser.

But since this files have to be created by php on server side, I cannot have browser involved. What I want to do, is to be able to emulate the browser and create an image from those files directly from php, in order to email them to the appropriate department.

I think this can be done in the following steps:

  1. Some executable program that can be run from Command Promt with an argument being my file
  2. PHP could send commands to Command Promt telling it to run "the created file" with that program which would generate the image.
  3. Then I would email that image

Example of usability

Lets say you are running extjs web application in your browser, right? There is no user interaction, it might stay running for days. Now without doing anything you want to send an image of your CPU performance graph to your testing department.

Does anyone know the best way of doing this? Thanks

Brian
  • 4,958
  • 8
  • 40
  • 56
  • You mean like, generate a print-screen of your page or something? – Havenard Apr 20 '14 at 21:16
  • the image looks exactly like it would have been in the browser. If html or JS creates i.e. ExtJS charts, I want to generate the picture of that chart in php without browser involvment – Brian Apr 20 '14 at 21:17
  • If you just need to render an image (let say a JPEG) or even a PDF it's easier to just use a graphic rendering library. – Paolo Apr 20 '14 at 21:19
  • I'm still unsure about what you mean. If you have JS generating this image with Canvas, I suppose you can rewrite your script with GD2 to create it in PHP. – Havenard Apr 20 '14 at 21:19
  • @Havenard: Lets say you are running extjs web application in your browser, right? There is no user interaction, it might stay running for days. Now without doing anything you want to send an image of your CPU performance graph to your testing department. – Brian Apr 20 '14 at 21:24
  • The client's CPU performance? – Havenard Apr 20 '14 at 21:32
  • Something this simple you could even generate using SVG, which is basically XML. Exemple here: http://www.svgbasics.com/lines.html – Havenard Apr 20 '14 at 21:35
  • No servers, it does not have to be CPU, there can be information in the database that every 5 minutes gets updated. I need to send the graph based on updated values – Brian Apr 20 '14 at 21:35
  • It is not that simple. First, in your example there in no html to image conversion. Second, you cannot generate thousands of points to fit into path variable to draw the graph. Third, JS needs to be run somehow to interpret the code to svg – Brian Apr 20 '14 at 21:41
  • Why does it need to be JS again? – Havenard Apr 20 '14 at 22:05
  • Beacuse the charts are creatd via extjs – Brian Apr 20 '14 at 22:09
  • Sorry, I'm not following. What exactly extjs offers that you must unnegotiably use it even in server-side? – Havenard Apr 20 '14 at 22:11
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/51069/discussion-between-brian-and-havenard) – Brian Apr 20 '14 at 22:14

2 Answers2

2

Use server - side graph image generator. You don't need to emulate the browser and then fetch back to server - it's way more complicated and unreliable.

I have used JPGraph (http://jpgraph.net) in few projects - it can generate graph images on server side into some temporary directory, and then you can either include into email or output to client. If you find jpGraph not suitable solution, take a look at alternatives:

But if you still find that fetching javascript output from client and bringing it back to server is your way to go, then you might want to take a look at http://wkhtmltopdf.org/.

Community
  • 1
  • 1
lubosdz
  • 4,210
  • 2
  • 29
  • 43
  • this is not free, right? Also I do not want to use their graphs, I want to use ExtJS charts. That is why I want to transform html document into image – Brian Apr 20 '14 at 21:25
  • JPGraph is free, and also some alternatives (see the link). WkhtmlToPdf is also free. – lubosdz Apr 20 '14 at 21:34
  • +1 for the answer, but i cannot accept it since this is not what i wanted :) – Brian Apr 21 '14 at 00:01
0

I found what I was looking for, even though it is a little late but still...

I am using phantomjs. It is really cool. You can write php file and give it to phantomjs, it will create image or pdf as if you screen capture from browser.

This is what the command looks like from phantomjs directory:

phantomjs "youJavascriptFile" "outputType" "fileName" "file"

Where

  • outputType can be 'letter' or 'width x height'
  • file can be a http path to your server's php file
  • youJavascriptFile is the js file where you use this other inputs and a little phantomjs magic to create an output.
Brian
  • 4,958
  • 8
  • 40
  • 56