#! /bin/bash # # Assumes you have the following packages or files: # - imagemagick # - http://ms.unimelb.edu.au/~trice/xkcd-info # - nitrogen # # The first time you run this script, you'll need to # manually set nitrogen to use the generated wallpaper. set -e # Change the following settings to whatever you feel like. img_file=/tmp/xkcd-img.png wp_file=$HOME/Pictures/Wallpapers/xkcd.png col="#680000" font="$HOME/.fonts/Humor-Sans.ttf" scale="100%" # Remove existing files. for f in $wp_file $img_file; do [[ -e $f ]] && rm -v $f done # Get the image first. We need its dimensions to format the # title and alt-text. convert -verbose $(xkcd-info img) -negate -background "$col" -alpha shape -resize "$scale" $img_file # Wait. while [ -n "$(ps auxc | grep convert)" ]; do sleep 0.25 done # How wide is the image? size=$(identify $img_file | awk '{print $3}' | awk -Fx '{print $1}') # Create images based on the title and alt text. convert -verbose \( -background transparent -fill "$col" -gravity center \ -font "$font" -interline-spacing 8 -pointsize 32 \ -size $size caption:"$(echo && xkcd-info title)" \) \ \( -size "${size}x8" canvas:transparent \) \ $img_file \ \( -size "${size}x8" canvas:transparent \) \ \( -background transparent -fill "$col" -gravity center \ -font "$font" -interline-spacing 8 -pointsize 16 \ -size $size caption:"$(xkcd-info alt)" \) \ -gravity Center -append $wp_file while [ -n "$(ps auxc | grep convert)" ]; do sleep 0.25 done # Update the wallpaper. [[ -e $wp_file ]] && nitrogen --restore echo Done.