Last active
January 16, 2020 14:02
-
-
Save andyexeter/3a5cce6f18da633960f6ecf34d21d9c5 to your computer and use it in GitHub Desktop.
ImageOptim Shell Script
This file contains hidden or 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 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