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

Diff of /trunk/webthumb

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 61 by dpavlin, Wed Feb 6 21:26:10 2008 UTC revision 65 by dpavlin, Wed Feb 6 23:59:09 2008 UTC
# Line 23  Line 23 
23  # HEAD (part or LWP perl library, it can be commented out)  # HEAD (part or LWP perl library, it can be commented out)
24  # nc (netcat, to simulate web server)  # nc (netcat, to simulate web server)
25  # xwininfo (standard part of X-clients)  # xwininfo (standard part of X-clients)
 # xwit (not so standard command, but very useful)  
26  # import (part of ImageMagick package)  # import (part of ImageMagick package)
27    # xdotool (much more useful than xwit for this purpose)
28  #  #
29  # It will create snapshot of following size  # It will create snapshot of following size
30  W=1024  W=1024
31  H=768  H=768
32    D=24
33    
34  # and then resize it to (comment out to disable)  # and then resize it to (comment out to disable)
35  #RESIZE=200x  #RESIZE=200x
36    
37  # turn locally visible Xnest server to watch progress  # turn locally visible server to watch progress
38  DEBUG=0  DEBUG=0
39  test ! -z "$3" && DEBUG=1  if [ ! -z "$3" ] ; then
40            echo "DEBUG turned on"
41            DEBUG=1
42            D=8
43    fi
44    
45  # wait for $WAIT seconds for page to load  # wait for $WAIT seconds for page to load
46  WAIT=30  WAIT=30
# Line 43  WAIT=30 Line 48  WAIT=30
48  # some configurable paths  # some configurable paths
49  BROWSER=mozilla-firefox  BROWSER=mozilla-firefox
50  XSERVER=Xvfb  XSERVER=Xvfb
 XWIT=xwit  
51  URL=$1  URL=$1
52  FILE=${2:-screenshot.jpg}  FILE=${2:-screenshot.jpg}
53    
# Line 58  if [ -z "$URL" ] ; then Line 62  if [ -z "$URL" ] ; then
62          exit 1          exit 1
63  fi  fi
64    
65  if [ -z "`which $XWIT`" ] ; then  if [ -z "`which xdotool`" ] ; then
66          echo "$0 really need $XWIT to operate. please install it."          echo "$0 need xdotool from http://www.semicomplete.com/blog/projects/xdotool/"
67          exit 1          exit 1
68  fi  fi
69    
# Line 82  else Line 86  else
86          exit 1          exit 1
87  fi  fi
88    
89  echo "starting X server $XSERVER"  DISPLAY_PORT=6042
90    
91    while netstat -ln | grep ":$DISPLAY_PORT " >/dev/null ; do
92            DISPLAY_PORT=`expr $DISPLAY_PORT + 1`
93    done
94    
95  export DISPLAY=:42  DISPLAY=:`expr $DISPLAY_PORT - 6000`
96    
97    echo "using DISPLAY=$DISPLAY"
98    
99  if [ "$DEBUG" == 1 ] ; then  if [ "$DEBUG" == 1 ] ; then
100          echo "Using locally visible debug server on $LOCAL_DISPLAY"          echo "using locally visible debug server on $LOCAL_DISPLAY"
101          Xnest -display $LOCAL_DISPLAY -ac -geometry ${W}x${H} -depth 24 $DISPLAY 2>/dev/null &          DISPLAY=$LOCAL_DISPLAY Xephyr -ac -screen ${W}x${H}x${D} $DISPLAY 2>/dev/null &
102  else  else
103          $XSERVER -ac -screen 0 ${W}x${H}x24 $DISPLAY 2>/dev/null &          echo "starting $XSERVER"
104            $XSERVER -ac -screen 0 ${W}x${H}x${D} $DISPLAY 2>/dev/null &
105  fi  fi
106    
107    if [ -z "$!" ] ; then
108            echo "ABORT: can't start X server!"
109            exit
110    fi
111  XSERVER_PID=$!  XSERVER_PID=$!
112  echo "using pid $XSERVER_PID for X server"  
113    echo "X server pid $XSERVER_PID"
114    
115  function kill_x_server() {  function kill_x_server() {
116          echo "Killing server $XSERVER_PID"          echo "Killing server $XSERVER_PID"
117          kill $XSERVER_PID          kill $XSERVER_PID
118          rm -f $FRAMESET          rm -f $FRAMESET
119          rm -fr $PROFILE_DIR          rm -fr $PROFILE_DIR
120            trap '' EXIT
121          exit 1          exit 1
122  }  }
123  trap 'kill_x_server' INT QUIT TERM SEGV EXIT  trap 'kill_x_server' INT QUIT TERM SEGV EXIT
# Line 126  echo "making 'Screenshot' profile in $PR Line 142  echo "making 'Screenshot' profile in $PR
142  $BROWSER -CreateProfile "Screenshot $PROFILE_DIR" 2>/dev/null | grep Success  $BROWSER -CreateProfile "Screenshot $PROFILE_DIR" 2>/dev/null | grep Success
143    
144  echo "launching browser $BROWSER with $URL"  echo "launching browser $BROWSER with $URL"
145  $BROWSER -P Screenshot -width $W -height $H $FRAMESET 2>/dev/null &  $BROWSER -P Screenshot -width $W -height $H -safemode $FRAMESET 2>/dev/null &
146  BROWSER_PID=$!  BROWSER_PID=$!
147    
148  function kill_browser() {  function kill_browser() {
# Line 136  function kill_browser() { Line 152  function kill_browser() {
152          kill $XSERVER_PID          kill $XSERVER_PID
153          rm -f $FRAMESET          rm -f $FRAMESET
154          rm -fr $PROFILE_DIR          rm -fr $PROFILE_DIR
155            trap '' EXIT
156          exit 1          exit 1
157  }  }
158  trap 'kill_browser' INT QUIT TERM SEGV EXIT  trap 'kill_browser' INT QUIT TERM SEGV EXIT
159    
160  echo "waiting for on_load event from browser $BROWSER_PID for ${WAIT}s"  function ping_browser() {
161            echo -n "ping browser"
162  # there is hard-coded limit here:          while ! ( $BROWSER -remote "ping();" 2>&1 ) >/dev/null ; do
163  # we will wait $WAIT sec for page to load and render                  RID=`xdotool search Restore 2>/dev/null`
164                    if [ ! -z "$RID" ] ; then
165                            echo -n "Esc"
166                            xdotool focus $RID
167                            xdotool key Escape
168                            sleep 1
169                    fi
170                    echo -n "."
171                    sleep 1
172            done
173            echo " OK"
174    }
175    
176  echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w $WAIT -p $PORT >/dev/null || echo "Timeout after $WAIT sec!"  ping_browser
177    
178  # get Mozilla Firefox window id (for resize)  # get Mozilla Firefox window id (for resize)
179  WINDOW_ID=`xwininfo -display $DISPLAY -root -tree | grep gecko | cut -d\" -f1 | sort -n | head -1`  WINDOW_ID=`xwininfo -display $DISPLAY -root -tree | grep gecko | cut -d\" -f1 | sort -n | head -1`
# Line 153  WINDOW_ID=`xwininfo -display $DISPLAY -r Line 181  WINDOW_ID=`xwininfo -display $DISPLAY -r
181  if [ -z "$WINDOW_ID" ] ; then  if [ -z "$WINDOW_ID" ] ; then
182          echo "can't find window with name 'Mozilla Firefox'"          echo "can't find window with name 'Mozilla Firefox'"
183          exit 1          exit 1
184    else
185            echo "working on firefox window $WINDOW_ID"
186  fi  fi
187    
188  # move window to foreground  xdotool search firefox
 $XWIT -display $DISPLAY -id $WINDOW_ID -pop  
189    
190  echo "resizing window $WINDOW_ID to maximum size"  xdotool focus $WINDOW_ID
191  $XWIT -display $DISPLAY -id $WINDOW_ID -move 0 0  xdotool key F11
 $XWIT -display $DISPLAY -id $WINDOW_ID -resize $W $H  
192    
193    ping_browser
194    
195  echo -n "wating for browser ping..."  $BROWSER -remote "openURL($FRAMESET)" 2>/dev/null
196  while ! ( $BROWSER -remote "ping();" 2>&1 ) >/dev/null ; do  
197          echo -n "."  echo "waiting for on_load event from browser $BROWSER_PID for ${WAIT}s"
198          sleep 1  
199  done  # there is hard-coded limit here:
200  echo  # we will wait $WAIT sec for page to load and render
201    
202    echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w $WAIT -p $PORT >/dev/null || echo "Timeout after $WAIT sec!"
203    
204  # try to deduce inside area of window  # try to deduce inside area of window
205    
# Line 186  fi Line 217  fi
217    
218  import -window $DUMP_ID $RESIZE $FILE  import -window $DUMP_ID $RESIZE $FILE
219    
220    if [ "$DEBUG" == 1 ] ; then
221            echo -n "press enter to exit! "
222            read
223    fi

Legend:
Removed from v.61  
changed lines
  Added in v.65

  ViewVC Help
Powered by ViewVC 1.1.26