How to remotely get web page print screen? Using linux/unix or php tools. User enters the page address and I want to save the appearance on the server (as a image).
Asked
Active
Viewed 855 times
1 Answers
2
You want a headless web browser (i.e. one that you can run from the command line with no graphical interface). One such possibility is PhantomJS, which uses the webkit rendering engine.
Specifically you want the render()
method.
From the Rendering example on the examples page, save the following as rasterize.js
:
var page = new WebPage(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 600, height: 600 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
}
And then run it:
phantomjs rasterize.js http://ariya.github.com/svg/tiger.svg tiger.png

Benjie
- 7,701
- 5
- 29
- 44