{"id":2028,"date":"2010-03-04T18:01:53","date_gmt":"2010-03-04T17:01:53","guid":{"rendered":"http:\/\/www.bitvolution.com\/?p=796"},"modified":"2010-03-04T18:01:53","modified_gmt":"2010-03-04T17:01:53","slug":"batch-optimise-images-with-a-single-command","status":"publish","type":"post","link":"https:\/\/www.tomfotherby.com\/blog\/index.php\/2010\/03\/batch-optimise-images-with-a-single-command\/","title":{"rendered":"Batch optimise Images with a single command"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/www.tomfotherby.com\/blog\/wp-content\/uploads\/2010\/03\/pageSpeedScreenshot.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.bitvolution.com\/files\/2010\/03\/pageSpeedScreenshot-300x128.png?resize=300%2C128\" alt=\"Screenshot of Page Speed in Firebug\" width=\"300\" height=\"128\" class=\"alignleft size-medium wp-image-797\" \/><\/a><br \/>\nI find the <a href=\"http:\/\/code.google.com\/speed\/page-speed\/\">Page Speed<\/a> tool from Google extremely helpful for optimising my websites. I have a tip which can save time if your website is failing the &#8220;<em>Optimize Images<\/em>&#8221; test. Using the in-built <a href=\"http:\/\/developer.yahoo.com\/yslow\/smushit\/\">Smush.it<\/a> is one option but if most of your images are jpegs, you can achieve the same result and save time using a command line tool called <strong>jpegtran<\/strong> with the <code>-optimise<\/code> parameter to do lossless compression and the <code>-copy none<\/code> parameter to strip out image meta-data.<\/p>\n<p><em>Disclaimer: As with any image processing always keep a copy of the original images.<\/em><\/p>\n<p>To install <strong>jpegtran<\/strong> in Ubuntu, do:<br \/><span class=\"iconTerminal\">sudo apt-get install libjpeg-progs<\/span><\/p>\n<ul class=\"tickList\">\n<li>To optimise a single jpeg image:<br \/><span class=\"iconTerminal\">jpegtran -copy none -optimise -outfile image.jpg image.jpg<\/span><\/li>\n<li>To optimise all jpegs in the current directory:<br \/><span class=\"iconTerminal\">for img in `ls *.jpg`; do jpegtran -copy none -optimise -outfile $img $img; done<\/span><\/li>\n<li>To optimise all jpegs in the current directory and all child directories:<br \/><span class=\"iconTerminal\">find . -name &#8220;*.jpg&#8221; -print0 | xargs -0 -I filename jpegtran -copy none -optimise -outfile filename filename<\/span><\/li>\n<\/ul>\n<p>If you need to optimise various image formats, there is a PHP CLI tool called <a href=\"http:\/\/github.com\/ecentinela\/smusher\">smusher<\/a> which uses <em>Smush.it<\/em> and can work recursively on directories. Might be worth a look. It would be nice if <em>Smush.it<\/em> had a API &#8211; their FAQ <a href=\"http:\/\/developer.yahoo.com\/yslow\/smushit\/faq.html#faq_api\">mentions they are working on it<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I find the Page Speed tool from Google extremely helpful for optimising my websites. I have a tip which can save time if your website is failing the &#8220;Optimize Images&#8221; test. Using the in-built Smush.it is one option but if most of your images are jpegs, you can achieve the same result and save time [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[82],"tags":[102,78,103],"class_list":["post-2028","post","type-post","status-publish","format-standard","hentry","category-web-design","tag-commandline","tag-graphics","tag-performance"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=2028"}],"version-history":[{"count":0,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2028\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=2028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=2028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=2028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}