-
-
Save dipnlik/4253291 to your computer and use it in GitHub Desktop.
Organize wallpapers according to aspect ratio
This file contains hidden or 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 | |
shopt -s nullglob # won't error if a glob has no match | |
wallpaper_dir="$HOME/Dropbox/Photos/Wallpapers" | |
cd $wallpaper_dir | |
files=(*jpg *jpeg *png *bmp) | |
for file in "${files[@]}" | |
do read -r width height <<< $(sips -g pixelWidth -g pixelHeight "$file" | awk '/pixel(Width|Height)/ {print $2}') | |
# Check if the file is a valid image, if not skip | |
[ -z "$width" ] && continue | |
# Test the ratio against my pre configured ones | |
case $(echo "scale=3;$width / $height" | bc) in | |
1.333) ratio="4:3" ;; | |
1.250) ratio="5:4" ;; | |
1.777) ratio="16:9" ;; | |
1.600) ratio="16:10" ;; | |
*) ratio="other_ratio" ;; | |
esac | |
echo "Moving $file to $ratio" | |
mv "$file" "$wallpaper_dir/${ratio/:/x}/" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment