Created
September 23, 2011 17:59
-
-
Save syranez/1238024 to your computer and use it in GitHub Desktop.
posix-compatible function definitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# fetches the first found image from $REDDIT_RSS subthread $SUB, | |
#+ converts it to your desktop size | |
#+ and sets it as wallpaper | |
# subreddit | |
SUB="jailbait" | |
# reddit rss-uri | |
REDDIT_RSS="http://www.reddit.com/r/"$SUB"/.rss" | |
WORKFOLDER="/home/syranez/Pictures/bg" | |
# convert the image to this size | |
IMAGE_SIZE="1680x1050" | |
# checks dependencies | |
#+ | |
#+ @return 1: missing dependencies | |
#+ @return 0: all ok | |
check () { | |
if [ -z `which wget` ]; then | |
return 1 | |
fi | |
if [ -z `which awsetbg` ]; then | |
return 1 | |
fi | |
return 0 | |
} | |
# prepares $WORKFOLDER | |
#+ | |
#+ @param workfolder | |
prepare () { | |
if ! [ -f "$1" ]; then | |
mkdir -p "$1"; | |
fi | |
} | |
# gets something from the internet | |
#+ | |
#+ @param source | |
#+ @param target | |
iget () { | |
wget -q "$1" -O "$2" | |
} | |
# exracts the image uri from the feed | |
#+ | |
getimageuri () { | |
IMAGEURI=`iget "$REDDIT_RSS" - | sed 's/i.img/\n&/g' | head -2 | tail -1 | cut -d "&" -f1 | sed 's/./http:\/\/&/'` | |
} | |
# fetches the image | |
#+ | |
getimage () { | |
getimageuri | |
iget "$IMAGEURI" "$WORKFOLDER/jb.jpg" | |
} | |
# converts the image in other sizes | |
#+ | |
#+ @param local image uri | |
convert () { | |
TEMP="$WORKFOLDER/jb_tmp.jpg" | |
cp "$1" "$TEMP" | |
mogrify -modulate 25,0,100 -quality 96 "$TEMP" | |
mogrify -resize 2560x -quality 96 "$TEMP" | |
mogrify -crop "$IMAGESIZE"+640+512 -quality 96 "$TEMP" | |
mogrify -blur 128 -quality 96 "$TEMP" | |
mogrify -resize 300x -quality 94 "$TEMP" | |
mogrify -bordercolor white -border 10 "$TEMP" | |
# composite -gravity center "$1" "$TEMP" "$TEMP" | |
cp "$TEMP" "$1" | |
} | |
# sets the image as wallpaper | |
# | |
#+ @param local image uri | |
setwallpaper () { | |
awsetbg -f "$1" | |
} | |
check | |
if [ "$?" -eq "2" ]; then | |
exit 1 | |
fi | |
prepare "$WORKFOLDER" | |
getimage | |
convert "$WORKFOLDER/jb.jpg" | |
setwallpaper "$WORKFOLDER/jb.jpg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment