/[scripts]/trunk/webthumb
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/webthumb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jul 26 13:28:53 2004 UTC (19 years, 8 months ago) by dpavlin
File size: 3703 byte(s)
check for xwit existence, resize is now optional, moves browser to 0,0 before
capturing

1 dpavlin 1 #!/bin/sh
2     #
3     # This script is based on work of mendel from
4     # http://www.lafferty.ca/software/webshots/webshot
5     # webshot: hackish thing to take a picture of a whole webpage.
6     #
7     # idea from sippey (http://www.sippey.com/2004/blog-snaps/)
8     # inspiration from bradfitz
9     #
10     # usage: webshot url filename
11     #
12     # JPEG seems to be the best format.
13     #
14     # Modified by Dobrica Pavlinusic 2004-07-25
15     # - include signal grabbing
16     # - dynamic vncserver display
17     # - correct WindowID parsing
18     # - wait for browser to load full page (useful on slow links)
19     #
20     # It will need follwing external utilities:
21     # vncserver
22     # mozilla-firefox
23     # HEAD (part or LWP perl library, it can be commented out)
24     # nc (netcat, to simulate web server)
25     # xwininfo (standard part of X-clients)
26     # xwit (not so standard command, but very useful)
27     # import (part of ImageMagick package)
28     #
29     # It will create snapshot of following size
30 dpavlin 2 W=1024
31     H=768
32 dpavlin 1
33 dpavlin 2 # and then resize it to (comment out to disable)
34     #RESIZE=200x
35 dpavlin 1
36     # some configurable paths
37     BROWSER=mozilla-firefox
38     XSERVER=vncserver
39 dpavlin 2 XWIT=xwit
40 dpavlin 1 URL=$1
41     FILE=${2:-screenshot.jpg}
42    
43     FRAMESET="`mktemp`.html"
44     PORT=8888
45    
46 dpavlin 2 if [ -z "$URL" ] ; then
47     echo "usage: $0 http://url.to.capture [screenshot.jpg]"
48     exit 1
49     fi
50    
51     if [ -z "`which $XWIT`" ] ; then
52     echo "$0 really need xwit to operate. please install it."
53     exit 1
54     fi
55    
56 dpavlin 1 echo -n "testing URL $URL "
57     if HEAD $URL >/dev/null ; then
58     echo "ok"
59     else
60     echo "FAILED"
61     exit 1
62     fi
63    
64     echo "starting vnc X server"
65    
66     export DISPLAY=`$XSERVER -geometry ${W}x${H} -depth 24 2>&1 \
67     | grep : | head -1 | cut -d: -f2 | sed 's/^/:/'`
68    
69     function kill_vnc() {
70     vncserver -kill $DISPLAY
71     rm -f $FRAMESET
72     }
73     trap 'echo "QUIT!" >&2; kill_vnc; exit 1' INT QUIT TERM SEGV
74    
75     # create frameset to load site and after site is loaded trigger this script
76     cat > $FRAMESET <<END_OF_FRAMESET
77     <html>
78     <head>
79     <frameset rows="0,*" border=0 frameborder=no framespacing=0 onload="window.frames['trigger_frame'].window.location.replace('http://localhost:$PORT');">
80     <frame src="about:blank" name="trigger_frame" scrolling=no marginwidth=0 marginheight=0>
81     <frame src="$URL" name="page_frame" scrolling=no>
82     </frameset>
83     </head>
84     </html>
85     END_OF_FRAMESET
86    
87     echo "Using frameset html $FRAMESET"
88    
89     echo "preview available with: vncviewer $DISPLAY"
90    
91     echo "making 'Screenshot' profile"
92     $BROWSER -CreateProfile Screenshot | grep Success
93    
94     echo "launching browser $BROWSER with $URL"
95     $BROWSER -id Screenshot -P Screenshot -width $W -height $H $FRAMESET 2>&1 >/dev/null &
96    
97     echo "staring web server (wait for page to load)"
98    
99     # there is hard-coded limit here:
100     # we will wait 60sec for page to load and render
101    
102     echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w 60 -p $PORT >/dev/null
103    
104     # get Mozilla Firefox window id (for resize)
105    
106     WINDOW_ID=`xwininfo -display $DISPLAY -name "Mozilla Firefox" | grep "Window id:" | cut -d" " -f4`
107    
108     if [ -z "$WINDOW_ID" ] ; then
109     echo "can't find window with name 'Mozilla Firefox'"
110     exit 1
111     fi
112    
113 dpavlin 2 # move window to foreground
114     $XWIT -display $DISPLAY -id $WINDOW_ID -pop
115 dpavlin 1
116     echo "resizing window $WINDOW_ID to maximum size"
117 dpavlin 2 $XWIT -display $DISPLAY -id $WINDOW_ID -move 0 0
118     $XWIT -display $DISPLAY -id $WINDOW_ID -resize $W $H
119 dpavlin 1
120    
121     echo -n "wating for browser ping..."
122     while ! ( $BROWSER -remote "ping();" 2>&1 ) >/dev/null ; do
123     echo -n "."
124     sleep 1
125     done
126     echo
127    
128     # try to deduce inside area of window
129    
130     DUMP_ID=`xwininfo -display $DISPLAY -id $WINDOW_ID -tree | grep 0x | grep -v ${W}x${H} | grep ${W}x | head -1 | sed 's/^ *//' | cut -d' ' -f1`
131    
132     if [ -z "$DUMP_ID" ] ; then
133     echo "can't find inside area of window. Using whole browser!"
134     DUMP_ID=$WINDOW_ID
135     fi
136    
137     echo "saving window $DUMP_ID to $FILE"
138 dpavlin 2 if [ ! -z "$RESIZE" ] ; then
139     RESIZE="-geometry $RESIZE"
140     fi
141     import -window $DUMP_ID $RESIZE $FILE
142 dpavlin 1
143     kill_vnc
144    

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26