/[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

Contents of /trunk/webthumb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Mon Jul 26 06:48:59 2004 UTC (17 years, 2 months ago) by dpavlin
File size: 3297 byte(s)
Inital commit to CVS of webthumb

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 W=800
31 H=800
32
33 # and then resize it to
34 RESIZE=200x
35
36 # some configurable paths
37 BROWSER=mozilla-firefox
38 XSERVER=vncserver
39 URL=$1
40 FILE=${2:-screenshot.jpg}
41
42 FRAMESET="`mktemp`.html"
43 PORT=8888
44
45 echo -n "testing URL $URL "
46 if HEAD $URL >/dev/null ; then
47 echo "ok"
48 else
49 echo "FAILED"
50 exit 1
51 fi
52
53 echo "starting vnc X server"
54
55 export DISPLAY=`$XSERVER -geometry ${W}x${H} -depth 24 2>&1 \
56 | grep : | head -1 | cut -d: -f2 | sed 's/^/:/'`
57
58 function kill_vnc() {
59 vncserver -kill $DISPLAY
60 rm -f $FRAMESET
61 }
62 trap 'echo "QUIT!" >&2; kill_vnc; exit 1' INT QUIT TERM SEGV
63
64 # create frameset to load site and after site is loaded trigger this script
65 cat > $FRAMESET <<END_OF_FRAMESET
66 <html>
67 <head>
68 <frameset rows="0,*" border=0 frameborder=no framespacing=0 onload="window.frames['trigger_frame'].window.location.replace('http://localhost:$PORT');">
69 <frame src="about:blank" name="trigger_frame" scrolling=no marginwidth=0 marginheight=0>
70 <frame src="$URL" name="page_frame" scrolling=no>
71 </frameset>
72 </head>
73 </html>
74 END_OF_FRAMESET
75
76 echo "Using frameset html $FRAMESET"
77
78 echo "preview available with: vncviewer $DISPLAY"
79
80 echo "making 'Screenshot' profile"
81 $BROWSER -CreateProfile Screenshot | grep Success
82
83 echo "launching browser $BROWSER with $URL"
84 $BROWSER -id Screenshot -P Screenshot -width $W -height $H $FRAMESET 2>&1 >/dev/null &
85
86 echo "staring web server (wait for page to load)"
87
88 # there is hard-coded limit here:
89 # we will wait 60sec for page to load and render
90
91 echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w 60 -p $PORT >/dev/null
92
93 # get Mozilla Firefox window id (for resize)
94
95 WINDOW_ID=`xwininfo -display $DISPLAY -name "Mozilla Firefox" | grep "Window id:" | cut -d" " -f4`
96
97 if [ -z "$WINDOW_ID" ] ; then
98 echo "can't find window with name 'Mozilla Firefox'"
99 exit 1
100 fi
101
102
103 echo "resizing window $WINDOW_ID to maximum size"
104 xwit -display $DISPLAY -id $WINDOW_ID -resize $W $H
105
106
107 echo -n "wating for browser ping..."
108 while ! ( $BROWSER -remote "ping();" 2>&1 ) >/dev/null ; do
109 echo -n "."
110 sleep 1
111 done
112 echo
113
114 # try to deduce inside area of window
115
116 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`
117
118 if [ -z "$DUMP_ID" ] ; then
119 echo "can't find inside area of window. Using whole browser!"
120 DUMP_ID=$WINDOW_ID
121 fi
122
123 echo "saving window $DUMP_ID to $FILE"
124 import -window $DUMP_ID -geometry $RESIZE $FILE
125
126 kill_vnc
127

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26