Created
September 15, 2012 08:33
-
-
Save samarpanda/3726988 to your computer and use it in GitHub Desktop.
Batch optimise images with a single command
This file contains 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
#For jpeg files | |
#Need to install jpegtran in ubuntu | |
sudo apt-get install libjpeg-progs | |
Usage tips: | |
#To optimise a single jpeg image: | |
jpegtran -copy none -optimise -outfile image.jpg image.jpg | |
#To optimise all jpegs in the current directory: | |
for img in `ls *.jpg`; do jpegtran -copy none -optimise -outfile $img $img; done | |
#To optimise all jpegs in the current directory and all child directories: | |
find . -name “*.jpg” -print0 | xargs -0 -I filename jpegtran -copy none -optimise -outfile filename filename | |
#For png files | |
#optipng is a great little command line tool in Linux that can be used to optimize images for web. | |
#Need to install optipng in ubuntu | |
sudo apt-get install optipng | |
Usage tips: | |
$ optipng infile.png -out outfile.png | |
$ optipng -k file1.png file2.tiff file3.gif | |
* -k option ensures that a backup of the original files are retained. Else, the original files will be over written – if they are PNG of course. | |
$ optipng -o5 file1.png file2.tiff file3.gif | |
* -o option indicates the levels of optimization. -o5 indicates 5 levels of optimization. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment