/[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 64 by dpavlin, Wed Feb 6 23:45:58 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
# Line 33  H=768 Line 33  H=768
33  # and then resize it to (comment out to disable)  # and then resize it to (comment out to disable)
34  #RESIZE=200x  #RESIZE=200x
35    
36  # turn locally visible Xnest server to watch progress  # turn locally visible server to watch progress
37  DEBUG=0  DEBUG=0
38  test ! -z "$3" && DEBUG=1  test ! -z "$3" && DEBUG=1
39    
# Line 43  WAIT=30 Line 43  WAIT=30
43  # some configurable paths  # some configurable paths
44  BROWSER=mozilla-firefox  BROWSER=mozilla-firefox
45  XSERVER=Xvfb  XSERVER=Xvfb
 XWIT=xwit  
46  URL=$1  URL=$1
47  FILE=${2:-screenshot.jpg}  FILE=${2:-screenshot.jpg}
48    
# Line 58  if [ -z "$URL" ] ; then Line 57  if [ -z "$URL" ] ; then
57          exit 1          exit 1
58  fi  fi
59    
60  if [ -z "`which $XWIT`" ] ; then  if [ -z "`which xdotool`" ] ; then
61          echo "$0 really need $XWIT to operate. please install it."          echo "$0 need xdotool from http://www.semicomplete.com/blog/projects/xdotool/"
62          exit 1          exit 1
63  fi  fi
64    
# Line 82  else Line 81  else
81          exit 1          exit 1
82  fi  fi
83    
84  echo "starting X server $XSERVER"  DISPLAY_PORT=6042
85    
86  export DISPLAY=:42  while netstat -ln | grep ":$DISPLAY_PORT " >/dev/null ; do
87            DISPLAY_PORT=`expr $DISPLAY_PORT + 1`
88    done
89    
90    DISPLAY=:`expr $DISPLAY_PORT - 6000`
91    
92    echo "using DISPLAY=$DISPLAY"
93    
94  if [ "$DEBUG" == 1 ] ; then  if [ "$DEBUG" == 1 ] ; then
95          echo "Using locally visible debug server on $LOCAL_DISPLAY"          echo "using locally visible debug server on $LOCAL_DISPLAY"
96          Xnest -display $LOCAL_DISPLAY -ac -geometry ${W}x${H} -depth 24 $DISPLAY 2>/dev/null &          DISPLAY=$LOCAL_DISPLAY Xephyr -ac -screen ${W}x${H}x24 $DISPLAY 2>/dev/null &
97  else  else
98            echo "starting $XSERVER"
99          $XSERVER -ac -screen 0 ${W}x${H}x24 $DISPLAY 2>/dev/null &          $XSERVER -ac -screen 0 ${W}x${H}x24 $DISPLAY 2>/dev/null &
100  fi  fi
101    
102    if [ -z "$!" ] ; then
103            echo "ABORT: can't start X server!"
104            exit
105    fi
106  XSERVER_PID=$!  XSERVER_PID=$!
107  echo "using pid $XSERVER_PID for X server"  
108    echo "X server pid $XSERVER_PID"
109    
110  function kill_x_server() {  function kill_x_server() {
111          echo "Killing server $XSERVER_PID"          echo "Killing server $XSERVER_PID"
112          kill $XSERVER_PID          kill $XSERVER_PID
113          rm -f $FRAMESET          rm -f $FRAMESET
114          rm -fr $PROFILE_DIR          rm -fr $PROFILE_DIR
115            trap '' EXIT
116          exit 1          exit 1
117  }  }
118  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 137  echo "making 'Screenshot' profile in $PR
137  $BROWSER -CreateProfile "Screenshot $PROFILE_DIR" 2>/dev/null | grep Success  $BROWSER -CreateProfile "Screenshot $PROFILE_DIR" 2>/dev/null | grep Success
138    
139  echo "launching browser $BROWSER with $URL"  echo "launching browser $BROWSER with $URL"
140  $BROWSER -P Screenshot -width $W -height $H $FRAMESET 2>/dev/null &  $BROWSER -P Screenshot -width $W -height $H -safemode $FRAMESET 2>/dev/null &
141  BROWSER_PID=$!  BROWSER_PID=$!
142    
143  function kill_browser() {  function kill_browser() {
# Line 136  function kill_browser() { Line 147  function kill_browser() {
147          kill $XSERVER_PID          kill $XSERVER_PID
148          rm -f $FRAMESET          rm -f $FRAMESET
149          rm -fr $PROFILE_DIR          rm -fr $PROFILE_DIR
150            trap '' EXIT
151          exit 1          exit 1
152  }  }
153  trap 'kill_browser' INT QUIT TERM SEGV EXIT  trap 'kill_browser' INT QUIT TERM SEGV EXIT
154    
155    function ping_browser() {
156            echo -n "ping browser"
157            while ! ( $BROWSER -remote "ping();" 2>&1 ) >/dev/null ; do
158                    RID=`xdotool search Restore 2>/dev/null`
159                    if [ ! -z "$RID" ] ; then
160                            echo -n "Esc"
161                            xdotool focus $RID
162                            xdotool key Escape
163                            sleep 1
164                    fi
165                    echo -n "."
166                    sleep 1
167            done
168            echo " OK"
169    }
170    
171    ping_browser
172    
173    $BROWSER -remote "openURL($FRAMESET)" 2>/dev/null
174    
175  echo "waiting for on_load event from browser $BROWSER_PID for ${WAIT}s"  echo "waiting for on_load event from browser $BROWSER_PID for ${WAIT}s"
176    
177  # there is hard-coded limit here:  # there is hard-coded limit here:
# Line 153  WINDOW_ID=`xwininfo -display $DISPLAY -r Line 185  WINDOW_ID=`xwininfo -display $DISPLAY -r
185  if [ -z "$WINDOW_ID" ] ; then  if [ -z "$WINDOW_ID" ] ; then
186          echo "can't find window with name 'Mozilla Firefox'"          echo "can't find window with name 'Mozilla Firefox'"
187          exit 1          exit 1
188    else
189            echo "working on firefox window $WINDOW_ID"
190  fi  fi
191    
192  # move window to foreground  xdotool search firefox
 $XWIT -display $DISPLAY -id $WINDOW_ID -pop  
   
 echo "resizing window $WINDOW_ID to maximum size"  
 $XWIT -display $DISPLAY -id $WINDOW_ID -move 0 0  
 $XWIT -display $DISPLAY -id $WINDOW_ID -resize $W $H  
193    
194    xdotool focus $WINDOW_ID
195    xdotool key F11
196    
197  echo -n "wating for browser ping..."  ping_browser
 while ! ( $BROWSER -remote "ping();" 2>&1 ) >/dev/null ; do  
         echo -n "."  
         sleep 1  
 done  
 echo  
198    
199  # try to deduce inside area of window  # try to deduce inside area of window
200    
# Line 186  fi Line 212  fi
212    
213  import -window $DUMP_ID $RESIZE $FILE  import -window $DUMP_ID $RESIZE $FILE
214    
215    if [ "$DEBUG" == 1 ] ; then
216            echo -n "press enter to exit! "
217            read
218    fi

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

  ViewVC Help
Powered by ViewVC 1.1.26