Optimize Image Files from Your Terminal
In many times you may need to optimze rapidly a bunch of images at your hands. There are handy utilities that can help you reduce image sizes with simple commands in the terminal. The following lists some of these tools:
1. OptiPNG: Advanced PNG Optimizer:
Get it for Mac OS X:
brew install optipng
For Linux Ubuntu:
apt-get install optipng
To optimize an image, run:
optipng <img-name>.png
To wildcard all images recursively in the current directory and sub directories:
find . -iname "*.png" -exec optipng -o7 {} \;
2. jpegoptim:
Install for Mac OS X:
brew install jpegoptim
Install for Linux Ubuntu:
sudo apt-get install jpegoptim
Run the next command to optimize an image, -m
controls the image quality (0-100):
jpegoptim -m70 <img-name>
Or optimize all recursively:
find . -iname "*.jpg" -exec jpegoptim -m80 -o -p {} \;
3. gifsicle:
Install for Mac OS X:
brew install gifsicle
For Linux Ubuntu:
sudo apt-get install gifsicle
The commands for single image, and a group of images respectively, are:
# for single image.
gifsicle --batch -V -O2 <image-name>.gif
# to start from cureent dir and go down.
find . -iname "*.gif" -exec gifsicle --batch -V -O2 {} \;
Aliases
Here are some aliases to keep commands nearby for fast run on the active directory images.
Be warn that those (also the previously mentioned commands) all alter the original images.
alias compress_png="optipng -o7 *.png"
alias compress_jpg="jpegoptim -m80 *.jpg"
alias compress_gif="gifsicle --batch -V -O2 *.gif"
You can tweak the optimization level and other options to suit your needs.
ImageOptim
If you’d like to use a GUI application, ImageOptim is a pretty open source one for Mac OS X that supports multiple image formats.
Happy mature optimization :) !