Skip to content

Instantly share code, notes, and snippets.

@shakna-israel
Created October 27, 2014 12:30
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 shakna-israel/2fca124d0993ea6b1926 to your computer and use it in GitHub Desktop.
Save shakna-israel/2fca124d0993ea6b1926 to your computer and use it in GitHub Desktop.
Automatic Image Compression Script
# Requires jpegoptim, pngquant, optipng, gifsicle as well as scour and python.
# The scour.py file should be located at ~/scour/scour.py
# IMPORTANT: This script OVERWRITES existing image files.
# Licensed under the MIT License
# The MIT License (MIT)
# Copyright (c) 2014 James Milne
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
jpegoptim -t -m50 --all-progressive *.jpg
sleep 3s
pngquant -f *.png
sleep 3s
optipng -o7 -strip all *.png
sleep 3s
find . -type f -name '*fs8.png' | while read f; do mv "$f.png" "${f%fs8.png}"; done
sleep 3s
gifsicle --batch -i *.gif
sleep 3s
_cwd="$PWD"
for file in $_cwd/*.svg
do
python ~/scour/scour.py -i ${file} -o ${file}.n --enable-comment-stripping --strip-xml-prolog
done
find . -type f -name '*.n' | while read f; do mv "$f" "${f%.n}"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment