Question

I know there is not a direct way to take a screen shot of a web page with PHP. What would be the most straightforward way to accomplish this? Are there any command line tools that could do this that I might be able to execute from a PHP script (I'm thinking something that would run in a 'NIX OS (OS X and/or Linux in particular)?

Edit: Or maybe some sort of web service I could access via SOAP or REST or ...

Edit #2: I found a related question discussing the CLI option, but I'd still be open to other methods if anyone knows of anything.

Was it helpful?

Solution

See webkit2png for an OSX commandline program that does this.

The page also mentions Linux alternatives.

[edit]: wkhtml2image is the newest kid in town, and it works better then anything else i've ever used.

[edit2]: As of 2014, PhantomJS seems to be the way to go, as it has the newest webkit version of the alternatives I know about.

OTHER TIPS

html2ps does a decent job for relatively simple pages, and it requires very little in terms of external binaries, meaning it's very easy to install/use. If you control the pages you'll be capturing, then you can ensure that they'll render appropriately in html2ps. If you're hoping to capture arbitrary URLs, however, I'm not sure that the PHP port of HTML2PS is up to the task. It's also not the fastest thing in the world (expect render times in the seconds for complex pages), but that doesn't really matter for some applications.

Not sure if this would be enough for you, because it has some added stuff there, but would be worth giving it a try: http://www.snap.com

You can use the GD functions imagegrabscreen() or imagegrabwindow() to take a screenshot, but they're only available on Windows at the moment.

It's possible to get a base64 encoded image of a site by using the Google pagespeed api. You can specify desktop or mobile views, but you are limited to an image of a certain size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top