Skip to content

Instantly share code, notes, and snippets.

@oskarsh
Created April 11, 2023 07:59
Show Gist options
  • Save oskarsh/4c88989c3c56d730fecc0f6be0456099 to your computer and use it in GitHub Desktop.
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
#!/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