Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

back in Windows I would use jpegtran program to process all of the images in a folder.

However, there doesn't seem to be an application in Ubuntu with UI for performing the same task. Obviously, I should do it from the terminal, but I have no idea how to perform a losless batch operation. All of the tutorials mention cropping etc., but I don't need those operations.

Therefore, my question is:

What should I type in the terminal to perform losless optimization (i. e. only strip meta data I guess) of the folder with images (e. g. "ExampleFolder).

Thank you in advance!

share|improve this question
    
Tried using jpegtran via wine? –  Meer Borg Mar 25 '13 at 12:04
    
That's the problem - I'd rather avoid Wine if there is a native solution. :) –  take2 Mar 25 '13 at 12:13
    
And it seems that Wine won't open jpegtran's exe, so it's definitely not an option. –  take2 Mar 25 '13 at 12:29
add comment

2 Answers

up vote 2 down vote accepted

Also, if you need jpegtran, you can find it in the libjpeg-turbo-progs package. This has all the optimisation features of its Windows counterpart but you have to use it via the command line and it's frankly, quite a pain to use.

There are other ways of looping over files, but here I'll use find. The following will look for *.jpgs in the current directory. (Note this is not the same as previous versions of this post, for simplicity)

cd /path/with/jpgs
find . -exec jpegtran -optimize -outfile "{}.opti.jpg" "{}" \;

If you want it to save over itself, you can. Change the -outfile argument to "{}".

share|improve this answer
    
OK, that seems great. Can you explain the following: 1. How does it know that it has to search in photos? Can I point to folder "Example" in Photos? 2. Where did you specify anything about "2010"? 3. I'd prefer it to retain the same name, I guess that this "opti.jpg" tells it to add "opti" suffix. –  take2 Mar 25 '13 at 12:48
    
@take2 Sorry I've revised this a bit since writing that part. I'll make it make sense. –  Oli Mar 25 '13 at 12:49
    
You can specify the directory that find works in with the first parameter. In the current example, it will just look at the current working directory. –  Oli Mar 25 '13 at 12:53
    
OK, how would I point to photos/example folder? –  take2 Mar 25 '13 at 13:00
    
It's probably just simpler to jump into that directory with cd, but again, you'd just change the . near the beginning to photos/example. Note that find will search subdirectories by default. If you're doing stuff like this, it's safer to move your files into a place that only has the stuff you want to work on. –  Oli Mar 25 '13 at 13:03
show 1 more comment

The simplest way is with a different tool (jpegoptim):

$ sudo apt-get install jpegoptim
$ cd /directory/with/my/jpgs
$ jpegoptim *.jpg
19112008152.jpg 2592x1944 24bit Exif IPTC  [OK] 654743 --> 624552 bytes (4.61%), optimized.
19112008153.jpg 1944x2592 24bit Exif  [OK] 516927 --> 503801 bytes (2.54%), optimized.
19112008154.jpg 2592x1944 24bit Exif IPTC  [OK] 943392 --> 911266 bytes (3.41%), optimized.
19112008155.jpg 2592x1944 24bit Exif IPTC  [OK] 919962 --> 894754 bytes (2.74%), optimized.
19112008156.jpg 2592x1944 24bit Exif  [OK] 869388 --> 836059 bytes (3.83%), optimized.
19112008157.jpg 2592x1944 24bit Exif  [OK] 815169 --> 787316 bytes (3.42%), optimized.
19112008158.jpg 2592x1944 24bit Exif IPTC  [OK] 481438 --> 445175 bytes (7.53%), optimized.
19112008159.jpg 2592x1944 24bit Exif  [OK] 686519 --> 660520 bytes (3.79%), optimized.
19112008160.jpg 2592x1944 24bit Exif  [OK] 326367 --> 287568 bytes (11.89%), optimized.
19112008161.jpg 1944x2592 24bit Exif  [OK] 331862 --> 295984 bytes (10.81%), optimized.

There are quite a few options:

jpegoptim v1.2.3  Copyright (c) Timo Kokkonen, 1996-2009.
Usage: jpegoptim [options] <filenames> 

  -d<path>, --dest=<path>
                  specify alternative destination directory for 
                  optimized files (default is to overwrite originals)
  -f, --force     force optimization
  -h, --help      display this help and exit
  -m[0..100], --max=[0..100] 
                  set maximum image quality factor (disables lossless
                  optimization mode, which is by default on)
  -n, --noaction  don't really optimize files, just print results
  -o, --overwrite overwrite target file even if it exists
  -p, --preserve  preserve file timestamps
  -q, --quiet     quiet mode
  -t, --totals    print totals after processing all files
  -v, --verbose   enable verbose mode (positively chatty)
  -V, --version   print program version

  --strip-all     strip all (Comment & Exif) markers from output file
  --strip-com     strip Comment markers from output file
  --strip-exif    strip Exif markers from output file
  --strip-iptc    strip IPTC markers from output file
  --strip-icc     strip ICC profile markers from output file
share|improve this answer
    
I'd prefer jpegtran, since I've seen that jpegoptim is not entirely lossless. –  take2 Mar 25 '13 at 12:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.