views:

111

answers:

4

I want to create an image what a web page looks like, e.g. create a small thumbnail of the html + images. it does not have to be perfect (e.g. flash /javascript rendering).

I will call use the code on linux, ideally would be some java library, but a command line tool would be cool as well.

any ideas?

+1  A: 

you can get it nearly perfect, and cross platform too, by using a browser plugin.

BrowserShots is an open source project that may have some code you can use.

also see:

Colin Pickard
It's hardly a programming solution.
Pavel Shved
have you looked at any of the links I provided? There are command line options, they all work on linux, exactly as the asker requires
Colin Pickard
cheers for the links, looks like some possible solutions in there.
JohnSmith
+1  A: 

To take a screenshot in the terminal with ImageMagick, type the following line into a terminal and then click-and-drag the mouse over a section of the screen:

import MyScreenshot.png

To capture the entire screen and after some delay and resize it, use the following command:

import -window root -resize 400×300 -delay 200 screenshot.png 

You may use a mixture of xwininfo and import to retrieve the window id of the browser and make a screenshot of that window. A bash script to automate this process would be something like this:

#!/bin/bash
window_id=`xwininfo -tree -root | grep Mozilla | awk '{print $1}'`
import -window $window_id -resize 100x100 tumb.png

This script will create a 100x100 screenshot of Firefox on the current directory under the name tumb.png

Several sources show how to run a bash script from inside a Java application, google can help you on that. If you are in a hurry, check this and this.

karlphillip
to clarify, this will be called by a stand alone software (not a ui software)... so need to be automatic
JohnSmith
I edited the answer above and added the information you are looking for.
karlphillip
+2  A: 

Try CutyCapt, a command-line utility. It uses Webkit for rendering and outputs in various formats (SVG, PNG, etc.).

Andrei
+1: This will do the job.
tur1ng
looks good, but I would like a solution that is free for commercial use
JohnSmith
actually, i think i might be mistaken, do I understand correctly that CutyCapt + QT are free to use for commercial use, uisng the LGPL license?http://qt.nokia.com/products/licensing
JohnSmith
Andrei
CutyCapt worked wonderful:aptitude install xvfbaptitude install qt4-dev-toolswget http://cutycapt.svn.sourceforge.net/viewvc/cutycapt/CutyCapt.tar.gz?view=tarmv CutyCapt.tar.gz\?view\=tar CutyCapt.tar.gztar xfz CutyCapt.tar.gz cd CutyCaptqmakemakeand that was it.cheers!
JohnSmith
A: 

If you're interested in Java, maybe you could look at browser automation using Selenium-RC http://seleniumhq.com

It's a little java server that you can install on the box and the program itself will execute remote commands in a web browser.

Steps like (this is pseudo code by the way, I code my Selenium in php and I can't recall 100% of the specifics off the top of my head)

selenium.location("http://foo.com")
selenium.open("/folder/sub/bar.html")
selenium.captureScreenshot("/tmp/" + this.getClass().getName() + "."
                               + testMethodName + ".png");

Actually, I just did a quick websearch for the exact syntax on that last one ... and this guy has a blog with what might actually be working code in java :) https://dev.youdevise.com/YDBlog/index.php?title=capture_screenshots_of_selenium_browser_&more=1&c=1&tb=1&pb=1

There's also a number of websites that provide this service "cross browser and OS" I just can't recall what they are. Basically they've got a cloud of every single operating system and browser combination, and they log on with each machine, take a screen and store it on their site for you to come back to in a few hours when they're done.

Ahh... another websearch and it's yours :) http://browsershots.org/

Alex C