diff --git a/.bin/wallpaper b/.bin/wallpaper index dc12802..2d4efd9 100755 --- a/.bin/wallpaper +++ b/.bin/wallpaper @@ -1,70 +1,96 @@ #!/bin/bash # # Compose and set a wallpaper from disc, URL or from top images on reddit.com. -# Edit the last line for a command that sets the wall in your window manager +# Edit the last line for a command that sets the wall in your window manager # # Usage: -# Use a local file. -# $ wallpaper /some/local/picture.jpg +# Use a local file. +# $ wallpaper /some/local/picture.jpg # -# Fetch and use a file from an URL. -# $ wallpaper http://www.somesite.com/with/image.png +# Fetch and use a file from an URL. +# $ wallpaper http://www.somesite.com/with/image.png # -# Fetch a random current top image from reddit (not marked NSFW). -# Edit $REDDITSUBS below to set which subreddits to check for images. -# $ wallpaper +# Fetch a random current top image from reddit (not marked NSFW). +# Edit $REDDITSUBS below to set which subreddits to check for images. +# $ wallpaper # # Adapted from http://redd.it/kp7kr -# Which subreddits should we check for images? -REDDITSUBS="earthporn+villageporn+itookapicture+specart+ImaginaryLandscapes+SpacePorn" -# How big should the foreground image be on the wallpaper? -IMAGESIZE="(6/10)" +######## TODO ######## +# +# - Add logic back in to handle non-Reddit files +# - Add logic to allow the NSFW switch to work +# - Add logic for Distro Specific Challenges (setwallpaper for example) + + +################################################ +### Start Variables ### +################################################ +REDDITSUBS=(earthporn villageporn itookapicture specart ImaginaryLandscapes SpacePorn) +#REDDITSUBS=(ginger gonewild hotchickswithtattoos xsmall) +NSFW=0 #Show NSFW Images 0=No,1=Yes +IMAGESIZE="(6/10)" # How big should the foreground image be on the wallpaper? +################################################ +### End Variables ### +################################################ -SOURCE="$1" -if [ "x$SOURCE" == "x" ]; then - # If no $SOURCE is specified, fetch a random current top image from reddit - SOURCE=$(wget -q http://www.reddit.com/r/$REDDITSUBS/.rss -O- | \ +function getSubFromArray { + numSubs=${#REDDITSUBS[*]} # Count how many elements in the array + echo ${REDDITSUBS[$((RANDOM%numSubs))]} +} + +function getRandomRedditImage { + #This section needs to have logic added to respect the NSFW switch above + cd "$TEMPDIR" || exit 1 + rndSub=`getSubFromArray` + echo "Pulling recent random image from $rndSub" + SOURCE=$(wget -q http://www.reddit.com/r/$rndSub/.rss -O- | \ sed 's//\n&/g' | \ grep -iv NSFW | \ egrep -oi '[a-z]+://[^; ]*.(jpg|jpeg|png)' | \ grep -v 'thumbs.reddit.com' | \ shuf -n1) -fi - -IMAGE=$(basename "$SOURCE") - -DIR=$(mktemp -d) -cd "$DIR" || exit 1 -trap 'rm -rf $DIR' EXIT - -if [ $(echo "$SOURCE" | grep '^[a-z]\+://') ]; then - wget -q "$SOURCE" -O "$IMAGE" || exit 1 -else - cp "$SOURCE" "$IMAGE" || exit 1 -fi - -BG="${IMAGE//.*}_bg.${IMAGE##*.}" -DEST="output.${IMAGE##*.}" - -RESOLUTION=$(xrandr 2>/dev/null | awk '/*/ {print $1}') -BGZOOM=$(echo "$RESOLUTION" | awk -Fx '{print $1*2 "x" $2*2}') -BGOFFSET=$(echo "$RESOLUTION" | awk -Fx '{print "+" $1/3 "+" $2/3}') -IMAGERES=$(echo "$RESOLUTION" | \ - awk -Fx '{print $1*'$IMAGESIZE' "x" $2*'$IMAGESIZE'}') + echo "Image URL: $SOURCE" + IMAGE=$(basename "$SOURCE") + wget -q "$SOURCE" -O "$IMAGE" || exit 1 + BG="${IMAGE//.*}_bg.${IMAGE##*.}" + DEST="output.${IMAGE##*.}" + echo "DEST: $DEST" +} -cp "$IMAGE" "$BG" || exit 1 +function transformImage { + cd "$TEMPDIR" || exit 1 + RESOLUTION=$(xrandr 2>/dev/null |grep "*"|awk '{ print $1 }') + BGZOOM=$(echo "$RESOLUTION" | awk -Fx '{print $1*2 "x" $2*2}') + BGOFFSET=$(echo "$RESOLUTION" | awk -Fx '{print "+" $1/3 "+" $2/3}') + IMAGERES=$(echo "$RESOLUTION" | awk -Fx '{print $1*'$IMAGESIZE' "x" $2*'$IMAGESIZE'}') + cp "$IMAGE" "$BG" || exit 1 + mogrify \( -modulate 25,0,100 \) \ + \( -resize $BGZOOM^ \) \ + \( -crop "$RESOLUTION""$BGOFFSET" \) \ + \( -blur 128 \) -quality 96 "$BG" -mogrify \( -modulate 25,0,100 \) \ - \( -resize $BGZOOM^ \) \ - \( -crop "$RESOLUTION""$BGOFFSET" \) \ - \( -blur 128 \) -quality 96 "$BG" + mogrify \( -resize ${IMAGERES} \) \ + \( -bordercolor white -border 10 \) "$IMAGE" + composite -gravity center "$IMAGE" "$BG" "$DEST" + mv $DEST /home/cpare/Pictures/ +} -mogrify \( -resize ${IMAGERES} \) \ - \( -bordercolor white -border 10 \) "$IMAGE" +function mkTempWorkingDir { + TEMPDIR=$(mktemp -d) + echo "TempDir: $TEMPDIR" + cd "$TEMPDIR" || exit 1 + trap 'rm -rf $TEMPDIR' EXIT +} -composite -gravity center "$IMAGE" "$BG" "$DEST" +function setwallpaper { + #Need to add logic here for Ubuntu/other distro identification & processing + gconftool-2 -t string -s /desktop/gnome/background/picture_filename /home/cpare/Pictures/$DEST +} -feh --bg-center "$DEST" +mkTempWorkingDir +getRandomRedditImage +transformImage +setwallpaper \ No newline at end of file