Installing JPEGTRAN on a Mac or Unix/Linux

JPEGtran is cool because it lets you optimize JPEG images losslessly by:

  1. Stripping meta data (meta is sometimes bulky and useless for web display)
  2. Optimizing Huffman tables or
  3. 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.

  1. 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
  2. Uncompres the package, e.g. tar -xzvf /tmp/libjpeg.tar.gz
  3. go to the directory that contains the uncompressed code, e.g. cd /tmp/jpeg-6b
  4. ./configure
  5. sudo 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

25 Responses to “Installing JPEGTRAN on a Mac or Unix/Linux”

  1. Mathieu Laurent Says:

    The ubuntu package : http://packages.ubuntu.com/intrepid/libjpeg-progs

    aptitude install libjpeg-progs

  2. David Says:

    Perhaps amazon should use jpegtran – the financial saving could be significant

  3. Stoyan Says:

    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/

  4. William Macdonald Says:

    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

  5. Optimize images for web - Image optimization/format conversion Says:

    [...] 4. jpegtran : It lets you optimize JPEG images loss less by: [...]

  6. jusintv Says:

    Perhaps amazon should use jpegtran – the financial saving could be significant

  7. RadCradt Says:

    It’s amazin ) up to 80% compress!
    Thanx!

  8. Mike Brittain Says:

    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/

  9. Mike Brittain Says:

    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/

  10. Vincent Voyer Says:

    Hello, the new package (v8b) can’t compile on MAC, there’s some problem with the configure script.

  11. Seymour Caprice Says:

    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.

  12. Eliza Schonaerts Says:

    Amazing web web page engine weblog! Preserve it up!

  13. Инструменты для минимизации размера изображений | Insight IT Says:

    [...] для минимизации JPEG без потери качества является jpegtran, используется достаточно [...]

  14. iphone hack|android hack|cheap mobile|free mobile app|android app Says:

    iphone hack|android hack|cheap mobile|free mobile app|android app…

    [...]Installing JPEGTRAN on a Mac or Unix/Linux / Stoyan’s phpied.com[...]…

  15. internet explorer mac Says:

    internet explorer mac…

    [...]Installing JPEGTRAN on a Mac or Unix/Linux / Stoyan’s phpied.com[...]…

  16. small office telephone system Says:

    small office telephone system…

    [...]Installing JPEGTRAN on a Mac or Unix/Linux / Stoyan’s phpied.com[...]…

  17. whats the latest Says:

    Bookmarked…

    It was entirely by accident that I obtained the link on Digg, however I was delighted I did…

  18. Installing JPEGTRAN on Ubuntu | The Daily Clone Says:

    [...] Source: http://www.phpied.com/installing-jpegtran-mac-unix-linux/ from a comment by a certain Mathieu Laurent. [...]

  19. Must Have Android Apps 2010 Says:

    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

  20. UK telephone Systems Says:

    I have tried this also, installing to linux. Not as easy as it may appear. But got it working.

  21. coding Says:

    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.

  22. Bubba Says:

    I got this installed on Ubuntu using the command “apt-get install libjpeg-progs”

  23. PCB board Says:

    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.

  24. Www.Villasinbali.Com Says:

    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.

  25. Remco Says:

    Hello from 2013! You can do install it on Mac now via:

    $ brew install libjpeg

    cheers!

Leave a Reply