Feature Request: Optimize JPEG Huffman Tables

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Feature Request: Optimize JPEG Huffman Tables

Post by the-ninth »

Hi,

It would be great if ImageMagick could losslessly reduce the size of a JPEG by optimizing the Huffman tables. Same as the command line tools jpegtran and jpegoptim, or online tools such as smush.it or kraken.io.

Check this website for more information: http://www.impulseadventure.com/photo/o ... -jpeg.html

I am looking to include the optimization in an image upload/resize process for a photo gallery framework, which already uses ImageMagick. For me none of these tools are satisfactory, the command line tools are often not available on hosting accounts and the online tools have a file size limit of 1 MB.

Cheers, Robert
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Feature Request: Optimize JPEG Huffman Tables

Post by fmw42 »

I believe that IM relies upon the libjpeg delegate library for any jpg processing. So it is really out of the hands of the IM developers and a question for the libjpeg developers. However, I will defer to the IM developers for final comments and any corrections to my statement.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Feature Request: Optimize JPEG Huffman Tables

Post by magick »

The libjpeg delegate libraries allows you to define Huffman tables so it can be done-- its always a question of time. We don't have any. For this enhancement we will need to depend on a user contribution or it will need to wait until ImageMagick 7 is complete in about 1 year.
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Feature Request: Optimize JPEG Huffman Tables

Post by the-ninth »

Hi,

Just found something in the documentation that says that the Huffman optimization is already done in Imagemagick:

http://www.imagemagick.org/script/formats.php

Am I confusing something here?

Cheers, Robert
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Feature Request: Optimize JPEG Huffman Tables

Post by magick »

If you set the optimize-coding define it causes the compression to compute optimal Huffman coding tables for the image. In most cases optimal tables save only a few percent of file size compared to the default tables.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Feature Request: Optimize JPEG Huffman Tables

Post by anthony »

I have updated this define in IM examples, JPEG writing options...
http://www.imagemagick.org/Usage/formats/#jpg_write

Thanks for the extra details.

However what is the default setting for the "jpeg:optimize-coding" define?

The above implies that optimal huffman tables are off by default, and need set 'true' to turn on
While the Formats page implies that it is on by default and you need to set 'false' to turn it off.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Feature Request: Optimize JPEG Huffman Tables

Post by magick »

Optimal coding is off by default because it requires an extra pass over the image slowing compression.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Feature Request: Optimize JPEG Huffman Tables

Post by anthony »

Thanks. I have updated IM examples JPEG Writing Control Options appropriately.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Feature Request: Optimize JPEG Huffman Tables

Post by the-ninth »

Guys,

Since which version is it off by default? Just tested with 6.6.6, and here optimize-coding=true produces the same file size as if omitting the parameter, while optimize-coding=false produces a slightly larger file (85KB instead of 83KB).

Cheers, Robert
Post Reply