Created
April 11, 2023 07:59
-
-
Save oskarsh/4c88989c3c56d730fecc0f6be0456099 to your computer and use it in GitHub Desktop.
This sorts all images that are not 1x1 aspect ratio and puts them in the widescreen folder. Make sure to change the image_direcory
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 | |
# Set the working directory with the images | |
image_directory="/home/Pictures/Stålenhag" | |
cd "$image_directory" | |
mkdir 'widescreen' | |
# Iterate over all jpg files in the directory | |
find . -iname "*.jpg" | while read -r image; do | |
# Get the image dimensions using ImageMagick's identify command | |
dimensions=$(identify -format "%wx%h" "$image") | |
width=$(echo "$dimensions" | cut -d 'x' -f 1) | |
height=$(echo "$dimensions" | cut -d 'x' -f 2) | |
# Check if width and height are valid numbers | |
if [[ $width =~ ^[0-9]+$ ]] && [[ $height =~ ^[0-9]+$ ]]; then | |
aspect_ratio=$(echo "scale=2; $width/$height" | bc) | |
# Check if the aspect ratio is greater than 1 (widescreen) | |
if (( $(echo "$aspect_ratio > 1" | bc -l) )); then | |
# Move the image to the widescreen folder | |
mv "$image" "widescreen/" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment