Search code examples
htmldebianscreenshotjpeg

How can i make a screenshot of an HTML page (jpeg, png, etc..)?


I just want to make a screenshot of the website like it is rendered in the browser and save it as an image programaticaly. Let's say i have a website, and i want a preview function when i scroll over a link.

From my research i found that i can start a firefox instance from command line, and there is some plugin that can make the screenshot and return it, than shutting down the instance.

But, in order to do this i need to start the xserver and i don't want to do this as it's potencialy dangerous for my server from a security point of view.

My ideea is to create a virtual machine on the server running xserver with firefox, and my script to connect to the virtual machine, start the firefox instance there, get the image and return it to the browser. This should be possible but seems to be very complicated.

So my question is: Do you know any other alternative to accomplish this in a more simple/elegant way? Your opinions are highly appreciated.


Solution

  • Ok, I found a good solution. I can use CasperJS/PhantomJS (http://casperjs.org/) or other headless browser, so I don't need the xserver running. Thanks all for support !