Skip to content

Instantly share code, notes, and snippets.

@m039
Created February 4, 2013 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m039/4704715 to your computer and use it in GitHub Desktop.
Save m039/4704715 to your computer and use it in GitHub Desktop.
Grab a quote from http://iheartquotes.com/api, generate image with the quote and embed it into wallpaper. (raw version)
#!/bin/sh
#
# quote api
#
alias getfortune='wget --timeout=3 -O - -q'
alias fortune='getfortune http://www.iheartquotes.com/api/v1/random'
alias myfortune='getfortune http://www.iheartquotes.com/api/v1/random?source=forrestgump'
OLD_IFS=$IFS
IFS=$'\t'
response=( `myfortune` )
IFS=$OLD_IFS
echo == Response:
echo ${response[*]}
#
# generate image
#
WALLPAPER_ORIGNAL="/home/m039/Desktop/wallpaper/girl.jpg"
WALLPAPER_RESULT="/home/m039/Desktop/wallpaper/tmp/girl_with_quote.jpg"
# FONT="/home/m039/Desktop/wallpaper/tmp/fonts/dirt2death.ttf"
# FONT="/home/m039/Desktop/wallpaper/tmp/fonts/Cocaine sans.ttf"
# FONT="/home/m039/Desktop/wallpaper/tmp/fonts/EpoXY_histoRy.ttf" # !
FONT="/home/m039/Desktop/wallpaper/tmp/fonts/DISINTEG.TTF" # ! "
# FONT="/home/m039/Desktop/wallpaper/tmp/fonts/CheapInk.ttf" # "
# FONT="/home/m039/Desktop/wallpaper/tmp/fonts/broken15.ttf"
QUOTE="“"
TEXT="${response[0]}"
#filter text
TEXT=$(echo $TEXT | sed 's/ *$//g') # chomp
TEXT=$(echo $TEXT | sed 's/^"//g')
TEXT=$(echo $TEXT | sed 's/"$//g')
TEXT=$(echo $TEXT | sed 's/http.*//g')
TEXT=$(echo $TEXT | recode html..ascii)
TEXT+=${QUOTE}
#filter author
AUTHOR="${response[1]}"
AUTHOR=$(echo $AUTHOR | sed 's/http.*//g')
AUTHOR=$(echo $AUTHOR | recode html..ascii)
echo == Filtered text:
echo $TEXT
echo == Filtered author:
echo $AUTHOR
BACKGROUND=none
FILL=white
TDIR=`mktemp -d`
convert_caption () {
OLD_IFS=$IFS
IFS=$'\n'
convert -font "$FONT" -background $BACKGROUND -fill $FILL -pointsize 20 "$@"
IFS=$OLD_IFS
}
pushd $TDIR > /dev/null
convert_caption -size 20x caption:"${QUOTE}" quote.png
convert_caption -pointsize 20 -size 400 caption:"${TEXT}" text.png
convert_caption -size 400 -gravity East caption:"${AUTHOR}" author.png
convert -background $BACKGROUND quote.png text.png +append result.png
convert -background $BACKGROUND result.png author.png -append result.png
popd > /dev/null
composite $TDIR/result.png -geometry +480+0 -gravity center $WALLPAPER_ORIGNAL $WALLPAPER_RESULT
display -window root $WALLPAPER_RESULT
rm -rf $TDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment