Installing JPEGTRAN on a Mac or Unix/Linux
JPEGtran is cool because it lets you optimize JPEG images losslessly by:
- Stripping meta data (meta is sometimes bulky and useless for web display)
- Optimizing Huffman tables or
- Convert a JPEG to progressive encoding
From my experience 1 is more important than 2 or 3 and 3 gives better results than 2 for images over 10K
Installation
I never had to install jpegtran before because all unix/linux machines I've touched already have it. And on windows you just copy a binary somewhere in your path.
Well, I got this MacBook now and it doesn't have jpegtran so had to figure it out myself. Here's how you can do it, worked for me on Mac OS should work on any unix/linux too.
BTW, jpegtran is part of a package of few tools known as libjpeg, so you'll be installing a few programs not only jpegtran.
- Get the source code from here. It's the file called
jpegsrc.v6b.tar.gz. Using cURL you can download like:
curl http://www.ijg.org/files/jpegsrc.v6b.tar.gz > /tmp/libjpeg.tar.gz - Uncompres the package, e.g.
tar -xzvf /tmp/libjpeg.tar.gz - go to the directory that contains the uncompressed code, e.g.
cd /tmp/jpeg-6b ./configuresudo make install
Done.
You can test your shiny new set of tools like this and get some help information about the various options:
> jpegtran -h > cjpeg -h > djpeg -h > rdjpgcom -h > wrjpgcom -h
You also test by optimizing my book cover from Amazon like:
curl http://ecx.images-amazon.com/images/I/41ckBp3bBUL._SL500_AA240_.jpg > oojs.jpg jpegtran -copy none -progressive oojs.jpg > oojs-opt.jpg
This gives you 10% smaller file with not a pixel of quality loss. Not bad, eh, for a minute of work, or less.
This entry was posted on Friday, January 16th, 2009 and is filed under images, performance, tools. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

January 16th, 2009 at 5:28 am
The ubuntu package : http://packages.ubuntu.com/intrepid/libjpeg-progs
aptitude install libjpeg-progs
January 18th, 2009 at 3:24 pm
Perhaps amazon should use jpegtran – the financial saving could be significant
January 19th, 2009 at 1:25 pm
Thanks Mathieu.
David, yes, definitely. Virtually every site out there can benefit from running jpegtran. I did an experiment with 10 000 random images from all over the web and this was the average – 11.45% savings if you run jpegtran. Details: http://yuiblog.com/blog/2008/12/05/imageopt-4/
January 22nd, 2009 at 4:23 pm
If you use a mac have a look at ImageOptim.
This will run your images through numerous JPEG and PNG optimizers and get the best from each,
William
February 10th, 2009 at 2:31 pm
[...] 4. jpegtran : It lets you optimize JPEG images loss less by: [...]
April 9th, 2009 at 7:48 am
Perhaps amazon should use jpegtran – the financial saving could be significant
December 7th, 2009 at 4:31 pm
It’s amazin ) up to 80% compress!
Thanx!
January 2nd, 2010 at 4:55 pm
If you’re copying and pasting instructions from this article, you’ll run into errors when unzipping the .tar.gz file because the filename has since been updated. Check the home page for the most recent version of “jpegsrc”.
http://www.ijg.org/
January 28th, 2010 at 10:43 am
I wrapped your suggestions for jpegtran in a Perl script that searches for JPEGs within a given path. Works like this:
$ ./optimize_jpegs.pl /path/to/you/images
Script is available here:
http://www.mikebrittain.com/blog/2010/01/27/batch-processing-your-jpegs-with-jpegtran/
August 10th, 2010 at 4:52 am
Hello, the new package (v8b) can’t compile on MAC, there’s some problem with the configure script.
November 28th, 2010 at 10:17 pm
Stoyan nice job. Concise and easy to follow instructions. I’ve also used your tips for compiling PNG tools. Thanks!
@Vincent – I was able to download and compile “jpegsrc.v8b.tar.gz” on my Mac G3 iBook. Runs great. The only thing I did differently than these instructions was this:
4. sudo ./configure
But that was just a bad habit mistake on my part… not sure what the consequences would be for this script, but it runs fine.
January 2nd, 2011 at 5:59 am
Amazing web web page engine weblog! Preserve it up!
February 13th, 2011 at 2:46 am
[...] для минимизации JPEG без потери качества является jpegtran, используется достаточно [...]
October 6th, 2011 at 1:32 am
iphone hack|android hack|cheap mobile|free mobile app|android app…
[...]Installing JPEGTRAN on a Mac or Unix/Linux / Stoyan’s phpied.com[...]…
January 23rd, 2012 at 8:21 am
internet explorer mac…
[...]Installing JPEGTRAN on a Mac or Unix/Linux / Stoyan’s phpied.com[...]…
February 10th, 2012 at 3:15 pm
small office telephone system…
[...]Installing JPEGTRAN on a Mac or Unix/Linux / Stoyan’s phpied.com[...]…
February 11th, 2012 at 9:07 am
Bookmarked…
It was entirely by accident that I obtained the link on Digg, however I was delighted I did…
September 13th, 2012 at 10:06 pm
[...] Source: http://www.phpied.com/installing-jpegtran-mac-unix-linux/ from a comment by a certain Mathieu Laurent. [...]
March 1st, 2013 at 7:09 am
Thank you a bunch for sharing this with all of us you really recognize what you’re speaking approximately! Bookmarked. Kindly additionally discuss with my website =). We could have a hyperlink trade arrangement among us
March 3rd, 2013 at 10:21 am
I have tried this also, installing to linux. Not as easy as it may appear. But got it working.
March 6th, 2013 at 12:28 pm
Normally I don’t learn post on blogs, but I would like to say that this write-up very compelled me to check out and do it! Your writing taste has been surprised me. Thank you, very nice post.
March 28th, 2013 at 1:00 pm
I got this installed on Ubuntu using the command “apt-get install libjpeg-progs”
April 19th, 2013 at 3:09 am
Simply want to say your article is as astounding. The clarity on your submit is simply cool and that i could think you’re knowledgeable on this subject. Fine with your permission allow me to seize your feed to stay updated with forthcoming post. Thanks a million and please keep up the enjoyable work.
April 21st, 2013 at 12:57 am
I am exploring on-line above Three hours nowadays, however I never identified any interesting post such as your own house. It is lovely worth adequate to me. In my view, when just about all online marketers as well as people built perfectly information since you have, the internet will probably be much more practical than before.
April 29th, 2013 at 5:33 pm
Hello from 2013! You can do install it on Mac now via:
$ brew install libjpeg
cheers!