19

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
JohnSmith
  • 4,538
  • 9
  • 25
  • 25
  • possible duplicate of [Command line program to create website screenshots (on Linux)](http://stackoverflow.com/questions/125951/command-line-program-to-create-website-screenshots-on-linux) – Colin Pickard Jul 23 '10 at 13:41

5 Answers5

15

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

Andrei
  • 1,606
  • 4
  • 19
  • 31
  • looks good, but I would like a solution that is free for commercial use – JohnSmith Jul 23 '10 at 13:39
  • 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 Jul 23 '10 at 13:57
  • According to CutyCapt's source code, it's license GNU v2 (see http://cutycapt.svn.sourceforge.net/viewvc/cutycapt/CutyCapt/CutyCapt.cpp?revision=6&view=markup). You don't need a commercial version of QT to use CutyCapt, so you should be fine. – Andrei Jul 23 '10 at 14:38
  • CutyCapt worked wonderful: aptitude install xvfb aptitude install qt4-dev-tools wget http://cutycapt.svn.sourceforge.net/viewvc/cutycapt/CutyCapt.tar.gz?view=tar mv CutyCapt.tar.gz\?view\=tar CutyCapt.tar.gz tar xfz CutyCapt.tar.gz cd CutyCapt qmake make and that was it. cheers! – JohnSmith Jul 23 '10 at 17:29
2

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:

Community
  • 1
  • 1
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
1

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
  • 92,053
  • 36
  • 243
  • 426
1

After reading this page, I was thinking, let me fire up midori browser: http://midori-browser.org/ and when I tried the -h option, I have seen:

  -s, --snapshot      Take a snapshot of the specified URI

QutyCapt is difficult to compile, and has many dependencies. Midori has it less. It outputs the PNG of the website into TMP folder. One can get the file with:

midori -s http://www.rcdwealth.com new.png 2>/dev/null | awk '{ print $4}'

After that, the file can be converted to thumbnail size by using ImageMagick's convert program.

Jean Louis
  • 425
  • 1
  • 4
  • 12
0

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
  • 16,624
  • 18
  • 66
  • 98