Cheat Logo

Cheat Sheet

Wallpaper script

Level: Intermediate
OS:
  • OS X
  • Linux
  • BSD
  • Solaris
Programs:
  • ImageMagick

When using a small image as a desktop wallpaper, it is often useful to expand the image background to fill the full screen. This script finds the background color of the original image, then expands it to the specified size. The shave statement is used for images with a one pixel border.

#!/bin/bash
# get colour
colour=`convert $1 -crop 1x1+1+1 txt:- | sed -n 's/.* \(#.*\) .*/\1/p'`
# crop & expand
mogrify -shave 1x1 -extent $2 -background $colour -gravity center $1
©2015 Schutt Design (Luke & Noel Schutt).
Contact us using one of our first names at schuttdesign dot net.