I want PhantomJS to generate a PNG
How fast can you setup a Node.js based solution which can generate and return a PNG screenshot of some HTML based on a request using PhantomJS?
22.58 Installing PhantomJS
PhantomJS I will need to render a webpage and then use PhantomJS to get a screenshoot of the rendered HTML.
Open the terminal to see if PhantomJS is already installed:
-bash: phantomjs: command not found
This means that it is not installed on my system. I visit PhantomJS website to download and install it.
I downloaded the ZIP file (I am on Mac) and after some looking around I decided to install the phantomjs app found in the bin folder to my “/usr/local/bin” folder. After I did that the “phantomjs” command could be found from the terminal.
Running that file simply took on command in the terminal:
The result was a screenshoot of my wordpress blog:
It took a little longer to get to that point, the time is now: 23.43.
23.45 All I need now is a local webserver with some content!
Ok, I will then create a simple Node.JS based website with some HTML. That should be easy!
23.59 It was easy. The above image (“hello world”) is a screenshoot of some content served using a Node.JS + Express based webserver. Now it is only a matter of building the HTML I need a screenshoot of. I have extended the gist to also contain the files needed to create the server.
Conclusion: It’s very easy to do something with such great software!