Taking a full color screenshot from the commandline with ImageMagick

0

I am trying to automate website screenshots on my (headless) server as follows:

Start a virtual X server:

Xfvb :1 -pixdepths 16,24,32 -screen 1 1080x1440x24 -nolisten tcp

First I tried taking screenshots with cutycaps:

DISPLAY=:1 cutycapt --url=http://myurl --out=screenshot.png

This works with full colors, but the webkit engine is too old to support our CSS, so the web page does not display properly.

So I tried Firefox and ImageMagick:

nohup firefox http://myurl &
sleep 4
import -display :1 -window root screenshot.png

Sadly, the resulting image has only 16? 256? colors. Definitely not enough.

So I tried xwd:

xwd -root -display :1 -out screenshot.xwd

Still no luck, still just 16 colors. Any ideas?

knipknap

Posted 2016-08-01T07:14:43.917

Reputation: 121

Answers

0

I found a solution. For some reason, full colors only work when Xfvb is running on display :0. So this works:

# Run Xfvb
Xfvb :0 -screen 0 1080x1440x24 -nolisten tcp &

export DISPLAY=:0

# Start Firefox.
nohup firefox http://fipla.spiff.xyz:8000/calendar &
FFPID=$!
sleep 3

# Resize the window.
WINDOW_ID=`xdotool search --onlyvisible firefox`
echo Window id is $WINDOW_ID
xdotool windowmove $WINDOW_ID 0 0
xdotool windowsize $WINDOW_ID 1080 1440
sleep 1

# Take screenshot.
import -window root -crop 1067x1380+0+72 $DIR/screenshot1.png

kill $FFPID
rm nohup.out

knipknap

Posted 2016-08-01T07:14:43.917

Reputation: 121