views:

7679

answers:

14

Hi,

Is there any way of taking a screenshot of a website in PHP, then saving it to a file?

Thanks

+2  A: 

I found this article that tells you how to do it (with code example). Scroll to the bottom to check it out.

http://www.plentyofcode.com/2007/09/website-screenshot-capture-with-aspnet.html

Jon
A: 

Not with out a plugin or client side code.

Daniel A. White
Why would you need client-side code? or a plugin for that matter?
Calvin
A: 

A website has to be rendered. PHP does not have website (HTML, CSS, JavaScript, etc) rendering capabilities. So no.

apphacker
Technically he's right. So far all the solutions involve calling an external program to render the page or generate the screenshot. Though command-line tools like khtmld seem like a viable solution. But PHP itself cannot take a screen shot of a webpage.
Calvin
A: 

whit plain php - no, you have to use some browser extensions, like activeX and other.

lfx
+1  A: 

Not directly. Software such as Selenium have features like this and can be controlled by PHP but have other dependencys (such as running their java-based server on the computer with the browser you want to screenshot)

Macha
+2  A: 

Yes. You will need some things tho:

See khtmld(aemon) on *nx. See Url2Jpg for Windows but since it is dotNet app you should also chek Url2Bmp

Both are console tools that u can utilise from your web app to get the screenshot.

There are also web services that offer it. Check this out for example.

Edit:

This link is useful to.

majkinetor
That's pretty cool.
apphacker
+3  A: 

It's in Python, but going over the documentation and code you can see exactly how this is done. If you can run python, then it's a ready-made solution for you:

http://browsershots.org/

Note that everything can run on one machine for one platform, or one machine with virtual machines running the other platforms.

Free, open source, scroll to bottom of page for links to documentation, source code, and other information.

Adam Davis
Its a bit overkill I think :)
majkinetor
http://store.schlockmercenary.com/PhotoGallery.asp?ProductCode=P-R37
Adam Davis
Rule 37: There is no overkill. There is only 'open fire', and 'time to reload'.
Adam Davis
+7  A: 

Sure you can, but you'll need to render the page with something. If you really want to only use php, i suggest you HTMLTOPS, wich render the page and output it in a ps file (ghostscript), then, convert it in a .jpg, .png, .pdf.. can be little slower with complex pages (and dont support all the CSS).

Else, you can use wkhtmltopdf to output a html page in pdf, jpg, whaterver.. Accept CSS2.0, use the webkit (safari's wrapper) to render the page.. so should be fine. You have to install it on your server, as well..

EDIT: i noticed now that the wkhtmltopdf team is working on another project: wkhtmltoimage, that gives you the jpg directly

DaNieL
+1 for wkhtmltopdf. I've toyed with some other libraries but none of them even came close to supporting anything more than very basic HTML and CSS. wkhtmltopdf can do everything that Safari does, so you're pretty safe there.
Wim
A: 

Shrink the web has always been what I've used. I think they have a nice API.

Splatzone
A: 

Guys, just use script bellow

<?php
echo  '<script language="javascript" src="http://www.bildesel.de/thumb.php?url='.urlencode($url).'"&gt;&lt;/script&gt;';
?>
A: 

Try this: http://www.websnapr.com/

Marcus Dau
A: 

This ought to be good for you:

http://code.google.com/p/wkhtmltopdf/

Make sure you download the wkhtmltoimage distribution!

Christian Sciberras
A: 

webkit2html works on Mac OS X and Linux, is quite simple to install and to use. See this tutorial.

For Windows, you can go with CutyCapt, which has similar functionality.

Piskvor
A: 

Realy Nice :d Thanks!

Steve