XKCD Fetch & Display

Posted in Images by Kename 1763 days ago

I use this to scrape the current http://xkcd.com/ comic and invert the image and set the background to transparent. Then another geeklet randomly displays the collected images.

You will need the command line tools from ImageMagik http://www.imagemagick.org/ in order to do the image manipulations in in the script.

The script below can be copied into a text file and saved as image.sh somewhere. I use ~/Pictures/XKCD to hold both the images and the script (largely so I can find it later).


cd ~/Pictures/XKCD
curl -s --location http://xkcd.com/ | grep embedding | sed 's/Image URL (for hotlinking\/embedding): \(.*\)/\1/w temp'
TEMP=$(cat temp)
rm temp
/opt/local/bin/mogrify -type Grayscale +negate -transparent black "$TEMP"

This started out pulling the image from http://dynamic.xkcd.com/random/comic/ but changed to reduce traffic. To switch back, you can replace the link in the script with the dynamic one.

Geeklet files to download


User Avatar
TehZomgie 1740 days ago

Log in to comment or register here.