Skip to content

Instantly share code, notes, and snippets.

@lukasbischof
Created September 16, 2018 21:21
Show Gist options
  • Save lukasbischof/653e2b465e5ec5d185d2ba8d6cd7feaa to your computer and use it in GitHub Desktop.
Save lukasbischof/653e2b465e5ec5d185d2ba8d6cd7feaa to your computer and use it in GitHub Desktop.
#!/bin/bash
files=(./*.JPG ./*.jpg)
count=${#files[@]}
if [ -d ./converted ]; then
echo "Converted directory already exists."
printf "Wipe existing one? [y/n]: "
read re
if [ $re == "y" ]; then
echo "Removing converted..."
rm -rf ./converted/*
else
echo "Aborting."
exit 1
fi
else
mkdir ./converted
fi
echo "Converting all *.jpg in dir $(pwd)"
for ((i=0; i<${#files[@]}; i++)); do
printf "\r$(($i*100/$count))%%\t[Image $(($i+1))/$count]"
file=${files[$i]}
convert $file -sampling-factor 4:2:0 -strip -quality 80 -interlace JPEG -colorspace sRGB -resize "45%" "converted/$file";
done
echo -e "\n100%\t[DONE!]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment