How to optimize whole folder like with jpegtran?
Solution 1
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 "{}"
.
Solution 2
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
Related videos on Youtube
take2
Updated on September 18, 2022Comments
-
take2 over 1 year
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 lossless 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 lossless optimization (i.e. only strip meta data I guess) of the folder with images (e.g.
ExampleFolder
).Thank you in advance!
-
take2 about 11 yearsI'd prefer jpegtran, since I've seen that jpegoptim is not entirely lossless.
-
Oli about 11 years@take2 Sorry I've revised this a bit since writing that part. I'll make it make sense.
-
Oli about 11 yearsYou 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. -
take2 about 11 yearsOK, how would I point to photos/example folder?
-
Oli about 11 yearsIt's probably just simpler to jump into that directory with
cd
, but again, you'd just change the.
near the beginning tophotos/example
. Note thatfind
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.