Skip to content

Instantly share code, notes, and snippets.

@0xa
Created September 7, 2014 20:00
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 0xa/a9f2f3777365d80250f8 to your computer and use it in GitHub Desktop.
Save 0xa/a9f2f3777365d80250f8 to your computer and use it in GitHub Desktop.
Wallpaper cache updater
#!/bin/zsh
size="$1"
input="../wallpapers/"
output="./wallpapers_$size/"
mkdir -p $output
walls_count=$(ls -1 $input | wc -l)
count=0
for wall in $input/*; do
(( count = $count + 1 ))
in_path="$input$(basename $wall)"
out_path="$output$(basename $wall)"
id=$(identify "$in_path" 2>>./identify_error)
echo -n "\r\033[Kresize[$count/$walls_count] $wall: "
if [ -f $out_path ]; then
echo -n "already exists"
continue
fi
id_geo=$(echo $id | sed 's/.\+ \([0-9]\+\)x\([0-9]\+\) .\+/\1 \2/')
set -- $id_geo
id_size=(${=id_geo})
size_x=$id_size[1]
size_y=$id_size[2]
echo "${size_x}x${size_y} -> $size";
convert "$in_path" -strip -resize ${size}\> "$out_path"
done
echo "\r\033[Kdone resizing; removing deleted items"
walls_count=$(ls -1 $output | wc -l)
count=0
for wall in $output/*; do
(( count = $count + 1 ))
in_path="$input$(basename $wall)"
out_path="$output$(basename $wall)"
echo -n "\r\033[Kclear[$count/$walls_count] $wall: "
if [ -f $in_path ]; then
echo -n "exists"
continue
fi
echo "deleted";
rm -- "$out_path"
done
echo "\r\033[Kdone"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment