Created
March 23, 2022 22:01
-
-
Save evoL/91ca6ef46253f315e17a8bd40efcdda2 to your computer and use it in GitHub Desktop.
Groups images in a directory into directories by resolution
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/sh | |
# Groups images in a directory into directories by resolution | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 SOURCE_DIRECTORY [TARGET_DIRECTORY]" >&2 | |
exit 1 | |
fi | |
SOURCE_DIRECTORY="$1" | |
TARGET_DIRECTORY="$2" | |
if [ ! -d "${SOURCE_DIRECTORY}" ]; then | |
echo "${SOURCE_DIRECTORY} needs to be a directory containing images." >&2 | |
exit 1 | |
fi | |
if [ ! -d "${TARGET_DIRECTORY}" ]; then | |
TARGET_DIRECTORY="${SOURCE_DIRECTORY}" | |
echo "Using ${SOURCE_DIRECTORY} as the target directory." | |
fi | |
for file in "${SOURCE_DIRECTORY}"/*; do | |
resolution=$(identify -format '%G' "${file}" 2>&1) | |
if [ $? -ne 0 ]; then | |
continue | |
fi | |
echo "${file}:\t${resolution}" | |
mkdir -p "${TARGET_DIRECTORY}/${resolution}" | |
mv "${file}" "${TARGET_DIRECTORY}/${resolution}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment