--- trunk/webthumb 2004/07/26 06:48:59 1 +++ trunk/webthumb 2008/02/06 19:48:56 60 @@ -27,21 +27,38 @@ # import (part of ImageMagick package) # # It will create snapshot of following size -W=800 -H=800 +W=1024 +H=768 -# and then resize it to -RESIZE=200x +# and then resize it to (comment out to disable) +#RESIZE=200x # some configurable paths BROWSER=mozilla-firefox -XSERVER=vncserver +XSERVER=Xvfb +XWIT=xwit URL=$1 FILE=${2:-screenshot.jpg} FRAMESET="`mktemp`.html" +PROFILE_DIR=`mktemp -d` PORT=8888 +if [ -z "$URL" ] ; then + echo "usage: $0 http://url.to.capture [screenshot.jpg]" + exit 1 +fi + +if [ -z "`which $XWIT`" ] ; then + echo "$0 really need $XWIT to operate. please install it." + exit 1 +fi + +if [ -z "`which $XSERVER`" ] ; then + echo "$0 really need $XSERVER to operate. please install it." + exit 1 +fi + echo -n "testing URL $URL " if HEAD $URL >/dev/null ; then echo "ok" @@ -50,16 +67,24 @@ exit 1 fi -echo "starting vnc X server" +echo "starting X server $XSERVER" + +export DISPLAY=:42 + +$XSERVER -ac -screen 0 ${W}x${H}x24 $DISPLAY & +# debug server +#Xnest -display :0 -ac -geometry ${W}x${H} -depth 24 $DISPLAY & -export DISPLAY=`$XSERVER -geometry ${W}x${H} -depth 24 2>&1 \ - | grep : | head -1 | cut -d: -f2 | sed 's/^/:/'` +XSERVER_PID=$! +echo "using pid $xserver_pid for X server" -function kill_vnc() { - vncserver -kill $DISPLAY +function kill_x_server() { + kill $BROWSER_PID + kill $XSERVER_PID rm -f $FRAMESET + rm -fr $PROFILE_DIR } -trap 'echo "QUIT!" >&2; kill_vnc; exit 1' INT QUIT TERM SEGV +trap 'echo "QUIT!" >&2; kill_x_server; exit 1' INT QUIT TERM SEGV # create frameset to load site and after site is loaded trigger this script cat > $FRAMESET <&1 >/dev/null & +$BROWSER -P Screenshot -width $W -height $H $FRAMESET & +BROWSER_PID=$! echo "staring web server (wait for page to load)" @@ -91,17 +117,19 @@ echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w 60 -p $PORT >/dev/null # get Mozilla Firefox window id (for resize) - -WINDOW_ID=`xwininfo -display $DISPLAY -name "Mozilla Firefox" | grep "Window id:" | cut -d" " -f4` +WINDOW_ID=`xwininfo -display $DISPLAY -root -tree | grep gecko | cut -d\" -f1 | sort -n | head -1` if [ -z "$WINDOW_ID" ] ; then echo "can't find window with name 'Mozilla Firefox'" exit 1 fi +# move window to foreground +$XWIT -display $DISPLAY -id $WINDOW_ID -pop echo "resizing window $WINDOW_ID to maximum size" -xwit -display $DISPLAY -id $WINDOW_ID -resize $W $H +$XWIT -display $DISPLAY -id $WINDOW_ID -move 0 0 +$XWIT -display $DISPLAY -id $WINDOW_ID -resize $W $H echo -n "wating for browser ping..." @@ -121,7 +149,11 @@ fi echo "saving window $DUMP_ID to $FILE" -import -window $DUMP_ID -geometry $RESIZE $FILE +if [ ! -z "$RESIZE" ] ; then + RESIZE="-geometry $RESIZE" +fi + +import -window $DUMP_ID $RESIZE $FILE -kill_vnc +kill_x_server