Skip to content

Instantly share code, notes, and snippets.

@pirafrank
Last active February 17, 2018 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirafrank/aaf3fc68134c58491e521d4403759462 to your computer and use it in GitHub Desktop.
Save pirafrank/aaf3fc68134c58491e521d4403759462 to your computer and use it in GitHub Desktop.
compress images to 85% quality (great quality/size ratio) using image_magick. Great to add DSLR pics to iCloud Photo Sync or similar services and save space.
#!/bin/bash
WORKDIR="${1%/}"
cd "$WORKDIR"
if [[ ! ./ -ef $WORKDIR ]]; then
echo "Error: cannot open given dir ($WORKDIR). Exiting..."
exit 1
fi
# creating ./output folder as subdir of input
mkdir "$WORKDIR"/output
if [ ! -d "$WORKDIR"/output ];then
echo "Error: cannot create output folder. Exiting..."
exit 1
fi
# shrinking image and setting modification date to shot time
for f in *.jpg *.JPG *.jpeg *.JPEG
do
echo "Processing $f ..."
fullname=$(basename "$f")
extension="${fullname##*.}"
filename="${fullname%.*}"
convert -format "jpg" -quality 85 $f output/"$filename""_lite.""$extension"
exiftool "-filemodifydate<datetimeoriginal" output/"$filename""_lite.""$extension"
#exiftool -overwrite_original_in_place -tagsFromFile $f output/"$filename""_lite.""$extension"
done
### output exif data to shell
# identify -format "%[EXIF:*]" $SOURCE
# exiftool -s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment