10/23/2015 - 1:09 PM


# this is needed by the apache server to run as the apache user
export USER=apache
export HOME=/var/www

# using a random virtual display, hopefully not one currently in use (maybe someday i'll make create a better way)
num=`expr $RANDOM % 900 + 10`

# this method uses vncserver to create a virtual X session i make this very long so i can get the whole page if i want, i also dont want to have
# scrollbars showing
vncserver -geometry 800x5000 :$num

# i sleep for 2 seconds to give it time to load
sleep 2

# open a firefox window on the random numbered display fullscreen and put it in the background
DISPLAY=:$num firefox-bin -fullscreen $1 &

# my site is local so i only wait 5 seconds, for other sites it'd be good to wait a little longer
sleep 5

# then use xwd to take the actual screenshot, maybe i'll use the random number in there sometime
xwd -display :$num -root > /tmp/screen-${num}.wd

# i dont want the full image so i scale it with imagemagicks convert, i also only want part of the image
convert -extract 800x600+0+0 -resize 100 /tmp/screen-${num}.wd $2

# when all is done and i have the screenshot i kill the X session
vncserver -kill :$num

# Cleanup temp file
rm -f /tmp/screen-${num).wd