tags:

views:

974

answers:

7

One problem I've been toying with off and on is a service that requires my server to produce a screenshot of a webpage at a given url. The problem is that I don't have any idea how I would accomplish this. I mostly use a LAMP software stack, so answers that were given with that in mind would be the most helpful. Again the basic requirements are: Given a url, the server needs to produce an image file of the rendered web page at that url. Thanks in advance!

+2  A: 

You actually need to have the server launch the web browser in question and take a screenshot of the application with the appropriate libraries. Apache will not render the page for you so you have to have software that will.

Orion Adrian
right. A couple of ideas that I had were to actually automatically collect a screenshot from the desktop environment, or somehow use the gecko engine to build a rendered version of the page that I could build an image from. Hmm....
Jurassic_C
+2  A: 

Yes, that is what is needed. I do this in asp.net, and I actually create a WebBrowser object that is avaialable in the .Net framework class libraries to generate the screenshot.

Vaibhav
+6  A: 

You might also want to take a look at webkit, it's known for being easier to embed (used by Adobe for AIR, by Google for Chrome, by Apple for the iPhone...) then other rendering engines. This might take a little more work to setup, but it would be a lot more stable than some hack that launched a webbrowser and took a screenshot.

davr
I like your thinking
Jurassic_C
+5  A: 

IF your server is a Mac, then I recommend webkit2png, which is a short python program that leverages WebKit's Objective-C API to render an URL. Personally, I use it in combination with WWW::Mechanize to walk my development site and make screenshots of every page -- useful for testing functionality, showing clients and keeping screenshots up-to-date. The resulting screenshot is perfect, but sometimes very tall for long, scrolling pages.

IF your server has a non-bare-bones Linux distro with KDE installed, then you might try khtml2png. I have not tried that myself, but saw it mentioned on the webkit2png page.

Chris Dolan
Somehow I don't think there are that many Mac servers out there, but khtml2png looks good too (if not as polished)
davr
+3  A: 

I use the http://webthumb.bluga.net service for thumbnail generation. Robust, powerful, easy to use, and very reasonable rates. I have a high traffic production website using this service and it works very well. Given the difficulty of creating a robust web screenshot service, it's nice to have someone else do the hard work.

Keeth
but it does not capture an entire website, it just thumbnails it.
PabloC
A: 

A non-free solution for Java is WebRenderer. Interesting feature: it can emulate Safari, IE or Firefox browsers when rendering. They have a desktop version and a headless server version. Also they have example code showing how to render a screenshot image of a webpage.

Keeth
A: 

virtual framebuffer X server

I would rather recommend XVFB (virtual framebuffer X server) is the best solution for taking screenshots of a headless server. Virtual framebuffer X server xvfb provides an X server that can run on machines with no display hardware and no physical input devices. I am using that on my server for testing URLs and taking its screenshot. We are using Ubuntu & XVFB + FIREFOX. It is working fine. Modify according to your needs. You can contact me any time if need help. (ankitsingh(DOT)05(AT)gmail.com) Take a look on this article. It might be use full for you.

http://www.semicomplete.com/blog/geekery/xvfb-firefox.html

http://linux.about.com/cs/linux101/g/xvfb.htm

http://www.xfree86.org/4.0.1/Xvfb.1.html

Ankit S