Web Page Screenshots with PHP?
Asked Answered
E

6

5

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.

Electroluminescence answered 26/3, 2009 at 17:51 Comment(0)
B
2

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.

[edit3]: In 2019, Puppeteer is the way to go. Official headless chrome, always up to date.

Blackcap answered 28/7, 2009 at 23:6 Comment(0)
M
1

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

Marrilee answered 26/3, 2009 at 17:56 Comment(0)
K
1

http://www.thumbshots.org/

Krisha answered 26/3, 2009 at 17:58 Comment(0)
H
1

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.

Honourable answered 26/3, 2009 at 18:19 Comment(0)
M
0

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

Mallen answered 26/3, 2009 at 17:54 Comment(0)
W
0

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.

Welbie answered 19/8, 2014 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.