Skip to content

Instantly share code, notes, and snippets.

@brinchj
Created June 6, 2010 10:23
Show Gist options
  • Save brinchj/427482 to your computer and use it in GitHub Desktop.
Save brinchj/427482 to your computer and use it in GitHub Desktop.
Script to blend background with text from yourworldoftext.com
#!/usr/bin/env zsh
# Dependencies:
# wget, Xvfb, ImageMagick, Xmonad/awesome/ratpoisen
# Configure path if neccessary
PATH=/home/jos/bin:$PATH
# Original background
BG_FILE="/home/jos/bg.png"
# Temperary directory for intermediate files
TMP_DIR="/var/tmp/ywot"
# Output background with text added
OUT_FILE="${TMP_DIR}/ready.png"
# URL to grab
URL="yourworldoftext.com"
TITLE="Your World of Text"
# Tiling window manager to start inside background X (ratpoisen, awesome, Xmonad, etc.)
WM="/home/jos/bin/xmonad"
# Web browser to open - surf gives good results ;-)
# http://surf.suckless.org/
WEB="/home/jos/bin/surf"
# Screen resolution
RES="1024x768x24"
# Create tmp dir
mkdir -p ${TMP_DIR}
# Got net?
wget ${URL} -O- &> /dev/null || exit 1;
# Start X
Xvfb :2 -screen 0 1024x768x24 -xinerama & pid_x=$!; sleep 1 &&
# Render page and grab screenshot
DISPLAY=:2 ${WM} & pid_wm=$!; sleep 2 &&
DISPLAY=:2 ${WEB} ${URL} & pid_web=$!; sleep 10 &&
DISPLAY=:2 win_id=`xwininfo -name "${TITLE}" | grep -Eo "0x[0-9a-z]+" | head -n1`;
DISPLAY=:2 import -window ${win_id} ${TMP_DIR}/mask.png
# Kill offspring
kill ${pid_web};
kill ${pid_wm};
kill ${pid_x};
# Preprocess browser shot
mogrify -transparent white -colors 16 -blur 1 -colorspace gray -enhance \
-resize 1440x ${TMP_DIR}/mask.png &&
# Blend images
composite -compose overlay -gravity northwest ${TMP_DIR}/mask.png ${BG_FILE} ${TMP_DIR}/bg.png &&
mv ${TMP_DIR}/bg.png ${OUT_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment