imager icon indicating copy to clipboard operation
imager copied to clipboard

How to use the libjpeg-turbo advanced option with Imager ?

Open zeroheure opened this issue 3 years ago • 7 comments

Is there a way to use the libjpeg-turbo advanced option with Imager ? libjpeg-turbo add some useful options to libjpeg. Some of them are really useful for current web images, like separate compression levels for luminance and chrominance or pre-defined quantization tables. I would like to pass these options in $img->write. Is it possible ?

zeroheure avatar Jul 03 '21 22:07 zeroheure

There isn't yet, but it's something that could be added.

tonycoz avatar Jul 05 '21 01:07 tonycoz

And is it curently possible, to force some of these options, like: jpeg_compression->'75,15' which would correspond to cjpeg -quality 75,15 option with libjpeg-turbo, or else passing a long string containing all options which wouldn't be parsed by Imager: -progressive -smooth 0 -dc-scan-opt 2 -optimize -sample 1x1 -tune-hvs-psnr

zeroheure avatar Jul 05 '21 10:07 zeroheure

I am only a sysadmin, not a real programmer. But I can understand C code. Could you tell me in which file(s) things should be changed ?

zeroheure avatar Jul 05 '21 11:07 zeroheure

JPEG/imjpeg.c mostly.

It would also need tests in JPEG/t.

tonycoz avatar Jul 06 '21 05:07 tonycoz

Imager 1.015 now supports much more JPEG output configuration, including support for mozjpeg's compression profile, though Imager defaults to "fast" compression for backward compatibility.

I think the only option missing from your list is multiple qualities (some of those options are mozjpeg options rather than libjpeg-turbo.)

tonycoz avatar May 07 '22 06:05 tonycoz

Wow thanks a lot! Actualy, multiple qualities is a libjpeg-turbo option. Look in libjpeg-turbo/main/usage.txt :

The -quality option has been extended in this version of cjpeg to support separate quality settings for luminance and chrominance (...) The -quality option accepts a comma-separated list of parameters, which respectively refer to the quality levels that should be assigned to the quantization table slots. (...) CAUTION: For this setting to be useful, be sure to pass an argument of -sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the default subsampling level (2x2, AKA "4:2:0") will be used.

zeroheure avatar May 07 '22 13:05 zeroheure

I've asked DRC from libjpeg-turbo about luminance and chrominance params. As you can see in his answer, cjpeg doesn't use jpeg_set_quality but rather jpeg_add_quant_table.

zeroheure avatar Sep 12 '22 17:09 zeroheure