Created
September 14, 2019 21:28
-
-
Save onebytegone/5093213eabad07a51f67c4788a039144 to your computer and use it in GitHub Desktop.
Script to pre-process images for a digital photo frame
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
#!/usr/bin/env bash | |
set -e | |
SRC_DIR=$1 | |
DEST_DIR=$2 | |
TMP_DIR=/tmp/photo-frame | |
if [ -z "${SRC_DIR}" ] || [ -z "${DEST_DIR}" ]; then | |
echo "Usage: $(basename $0) ./src-dir ./dest-dir" | |
exit | |
fi | |
mkdir -p "${TMP_DIR}" | |
rsync -aP --delete "${SRC_DIR}" "${TMP_DIR}" | |
pushd "${TMP_DIR}" | |
echo 'File type found:' | |
ls | awk -F '.' '{print $NF}' | sort | uniq -c | |
for EXT in $(ls | awk -F '.' '{print $NF}' | sort | uniq); do | |
if [[ "${EXT}" != 'jpg' ]]; then | |
echo "Converting ${EXT} files to jpg..." | |
mogrify -monitor -format jpg "*.${EXT}" | |
fi | |
done | |
echo 'Applying exif orientation...' | |
mogrify -monitor -auto-orient "*.jpg" | |
echo 'Syncing images to destination...' | |
mkdir -p "${DEST_DIR}" | |
rsync -aP --delete --include '*/' --include '*.jpg' --exclude '*' "${TMP_DIR}" "${DEST_DIR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment