tjko / jpegoptim

jpegoptim - utility to optimize/compress JPEG files
http://www.iki.fi/tjko/projects.html
GNU General Public License v3.0
1.56k stars 116 forks source link

Unexpected behaviour with -S flag on collections of files #76

Closed dfaligertwood closed 2 years ago

dfaligertwood commented 3 years ago

When the -S flag is used on a collection of files, only the first file in a folder has its size optimised, everything else reuses the same compression setting:

⋊> ~/P/Q/c/test jpegoptim -S100 -dtest -v *.jpg                                                              14:14:06
Target size for output files set to: 100 Kbytes.
IMG_00000003.jpg 2448x2448 24bit N Exif  [OK] (try 50)(try 25)(try 12)(try 5)(try 9)(try 11)(try 10)(try 9)(revert to 10) 1569612 --> 103681 bytes (93.39%), optimized.
IMG_00000005.jpg 2448x2448 24bit N Exif  [OK] (try 100)(revert to 10) 1057741 --> 59467 bytes (94.38%), optimized.
IMG_00000006.jpg 2448x2448 24bit N Exif  [OK] (try 100)(revert to 10) 1159410 --> 58513 bytes (94.95%), optimized.
IMG_00000007.jpg 2448x2448 24bit N Exif  [OK] (try 100)(revert to 10) 1058248 --> 52412 bytes (95.05%), optimized.
IMG_00000008.jpg 1200x1200 24bit N Exif  [OK] (try 100)(revert to 10) 236638 --> 14867 bytes (93.72%), optimized.
IMG_00000009.jpg 1200x1200 24bit N Exif  [OK] (try 100)(revert to 10) 231732 --> 14749 bytes (93.64%), optimized.

This may be intentional, but if so should probably be noted in the documentation?

Jpegoptim version:

jpegoptim v1.4.6  x86_64-apple-darwin19.0.0
Copyright (C) 1996-2018, Timo Kokkonen

This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistirbute it under certain conditions.
See the GNU General Public License for more details.

libjpeg version: 9d  12-Jan-2020
Copyright (C) 2020, Thomas G. Lane, Guido Vollbeding
tjko commented 2 years ago

This is a clearly a bug. Binary search for for quality factor that will produce desired size only run fully on first file (since one variable was not reset correctly before next binary search).

Fix is now checked in: 88a500048615ca834195deb574a836449bdf4a34