PHOTOS - Sort to Landscape or Portrait folder

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
xinu
Level 3
Level 3
Posts: 148
Joined: Fri Apr 24, 2015 1:39 am

PHOTOS - Sort to Landscape or Portrait folder

Post by xinu »

Hello Minters,

Maybe I should 've put this under 'Multimedia', but still,

hereby a full bash script I've written (and translated from my mother tongue) to seperate horizontal (landscape) or vertical (portrait) pictures from one dir to a 'Landscape' and a 'Portrait' dir.

I've named the script '0000_Photos_Sort_to_Portrait_or_Landscape.sh' (starting with 0000 to make it land on top of the input dir)

Tweak to your personal desires.
Give the script convenient rights.
Reply if you see sth that could be done in a better way.

Code: Select all

#!/bin/bash

echo -en '\e[8;14;80t' # Window Size

TITEL="PHOTOS - SORT TO PORTRAIT OR LANDSCAPE"
echo -en "\033]0;$TITLE\a" # Window Title

clear

echo "$TITLE"

echo

echo "Place this script in a dir with horizontal and vertical photos."
echo "A new folder will be created for each type."
echo "Makes use of imagemagick resolution recognition."

echo

echo "Source Extension (Default jpg, without dot)?"

read -e -i "jpg" -p "" SOURCEEXT

echo

# Codes:

mkdir -p Portrait
mkdir -p Landscape
for f in ./*.${SOURCEEXT}
do
  r=$(identify -format '%[fx:(h>w)]' "$f")
  if [[ r -eq 1 ]] 
  then
  echo "Vertical pictures moved to folder Portrait..."
  mv "$f" ./Portrait/
  else
  echo "Horizontal pictures moved to folder Landscape..."
  mv "$f" ./Landscape/
  fi
done

echo

echo "Enter = Reload Script"
echo "Ctrl+c or Close button = Close"

read

exec bash "$0" "$@" # Restart script from the beginning
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
rossdv8
Level 7
Level 7
Posts: 1737
Joined: Wed Apr 23, 2014 4:48 am
Location: Within 2,000 kilometres of Alice Springs, Australia
Contact:

Re: PHOTOS - Sort to Landscape or Portrait folder

Post by rossdv8 »

TITEL="PHOTOS - SORT TO
Is that a typo? or is Title spelled that way intentionally for some reason?
Current main OS: MInt 21.3 with KDE Plasma 5.27 (using Compiz as WM) - Kernel: 6.5.0-15 on Lenovo m900 Tiny, i5-6400T (intel HD 530 graphics) 16GB RAM.
Sharks usually only attack you if you are wet
Locked

Return to “Scripts & Bash”