Skip to content

Instantly share code, notes, and snippets.

@andyexeter
Last active January 16, 2020 14:02
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 andyexeter/3a5cce6f18da633960f6ecf34d21d9c5 to your computer and use it in GitHub Desktop.
Save andyexeter/3a5cce6f18da633960f6ecf34d21d9c5 to your computer and use it in GitHub Desktop.
ImageOptim Shell Script
#!/usr/bin/env sh
# Optimise images using the ImageOptim API
# Usage example: find images/ -type f -print0 | xargs -0 -n 1 -P 0 ./imageoptim.sh
# Usage example 2: ./imageoptim.sh file.jpg
# ImageOptim API Key (https://imageoptim.com/api/register)
api_key=''
for file in "$@"
do
orig_size=$(du -k $file | cut -f1)
curl -sL -F file=@"$file" -o "$file" "https://im2.io/$api_key/full"
new_size=$(du -k $file | cut -f1)
saving=$(($orig_size - $new_size))
echo "Optimised $file ${orig_size}KB > ${new_size}KB (${saving}KB saved)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment