Skip to content

Instantly share code, notes, and snippets.

@cpu
Last active August 29, 2015 13:57
Show Gist options
  • Save cpu/9589366 to your computer and use it in GitHub Desktop.
Save cpu/9589366 to your computer and use it in GitHub Desktop.
Generate random p4m tile backgrounds with ImageMagick and feh.
#!/bin/bash
################################################################################
# About
################################################################################
#
# Dumb script to generate a random 100x100 tile in the p4m background group.
# Uses 'feh' to tile the image as a desktop background.
#
# Install to crontab -e to rengerate at a fixed interval. E.g. every 5 min:
# */5 * * * * /home/youruser/bin/someplace/you/put/this/script.sh
#
# Credit goes primarily to the docs, I haven't deviated much:
# http://www.imagemagick.org/Usage/canvas/#tile_diagonal
# From there it was just a matter of tweaking params wildly until the desired
# effects are obtained. Yay art.
#
# For big smooshy looking plasma effects try a larger tile size (e.g. 200x200)
# and a higher blur (e.g. 0x10). Set GRAYSCALE=1 if you find the colours bright
# and distracting.
#
# - Daniel McCarney - [email protected]
################################################################################
################################################################################
# Tile Gen Params
################################################################################
# Size of each indidivual tile ( widthxheight in pixels )
TILE_SIZE=100x100
# Amount of blur to apply
BLUR=0x4
# Brightness and contrast. Negative to reduce, positive to increase.
BRIGHTNESS=-10
CONTRAST=-30
# If 1, output in grayscale. Otherwise map to RGB
GRAYSCALE=0
################################################################################
TMP_FILE=$(mktemp --suffix='.jpg')
if [ $? -ne 0 ]; then
echo "Error: unable to create temp file. Is 'mktemp' working?"
exit 1
fi
if ! type "convert" &> /dev/null; then
echo "Error: You must install ImageMagick and have 'convert' on your \$PATH."
exit 1
fi
if ! type "feh" &> /dev/null; then
echo "Error: You must install feh and have it on your \$PATH."
exit 1
fi
if [ $GRAYSCALE -ne 0 ]; then
OUTPUT_COLOURSPACE=gray
else
OUTPUT_COLOURSPACE=RGB
fi
convert -size $TILE_SIZE xc: +noise Random \( +clone -transpose \) \
\( +clone -sparse-color voronoi '%w,0 blue 0,%h red' \) \
-composite \
\( +clone -rotate -90 \) +append \
\( +clone -rotate 180 \) -append \
\
-virtual-pixel Tile -blur $BLUR -auto-level \
-separate -background white \
-compose ModulusAdd -flatten -channel R -combine +channel \
-set colorspace HSB -colorspace $OUTPUT_COLOURSPACE \
-brightness-contrast $BRIGHTNESSx$CONTRAST $TMP_FILE
export DISPLAY=:0 #Feh gets mad in a cronjob if it doesn't know the DISPLAY
feh --bg-tile $TMP_FILE
rm $TMP_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment