mozjpeg icon indicating copy to clipboard operation
mozjpeg copied to clipboard

Expose option to keep ICC profiles in jpegtran copy

Open inian opened this issue 9 years ago • 10 comments

Stripping out ICC profiles from jpegs can lead to lossy compression and since jpegtran seems to be a tool to do lossless transformations on images, it would be good to expose an option to not strip out ICC as part of jpegtran -copy command like jpegtran -copy skip-icc

It might be good to keep that as a default setting even.

inian avatar Aug 30 '16 04:08 inian

This issue is very important.
The default behavior of deleting color profile is also kind of dangerous. There's no warning, just a visually degraded result.

magicgoose avatar May 02 '18 09:05 magicgoose

looks like jpegtran -copy skip-icc is no longer available for the current version. The only way solution I've found is to leave it as jpegtran -copy all but I want to know if there is any other way to leave the ICC profile intact while stripping other metadata like comments and etc.

photoup-godwinh avatar Jun 12 '18 16:06 photoup-godwinh

Please consider adding this feature. A workaround is to save the profile with imagemagick and add it again with jpegtran:

magick original.jpg profile.icm
jpegtran -copy none -icc profile.icm original.jpg > stripped.jpg

joshuakraemer avatar Jul 10 '21 08:07 joshuakraemer

Is this a regression in MozJPEG? If it's not, please add it to libjpeg-turbo first.

kornelski avatar Jul 10 '21 09:07 kornelski

I am open to such an option, but I need to understand why it is necessary. Please explain the workflow under which one would discard other metadata while keeping the ICC profile.

dcommander avatar Jul 13 '21 15:07 dcommander

Please explain the workflow under which one would discard other metadata while keeping the ICC profile

I can only say for myself: while trying to lower a footprint of an image, discarding metadata won’t affect how the image looks. Discarding an ICC profile (and DCF EXIF tags) will actually change the appearance of an image, so it’s destructive. Less destructive is removal of orientation metadata, because (most of the time), it can be fixed manually. Once the colour info is stripped from an image, there is next to no way of telling how it was supposed to look like.

The only (relatively!) safe ICC info to strip is an sRGB profile (or – tag). But even then some browsers will still display wrong colours for such imagery.

paperboyo avatar Jul 13 '21 15:07 paperboyo

Please explain the workflow under which one would discard other metadata while keeping the ICC profile

I can only say for myself: while trying to lower a footprint of an image, discarding metadata won’t affect how the image looks. Discarding an ICC profile (and DCF EXIF tags) will actually change the appearance of an image, so it’s destructive. Less destructive is removal of orientation metadata, because (most of the time), it can be fixed manually. Once the colour info is stripped from an image, there is next to no way of telling how it was supposed to look like.

The JPEG data does not change when you discard the ICC profile, so it is incorrect and hyperbolic to use words such as "destructive" or "lossy" to describe this.

Please help me understand why reducing the size of an image by a few kilobytes at most is so important.

dcommander avatar Jul 13 '21 15:07 dcommander

@dcommander I think it's a valid optimization to remove everything except the ICC profile.

Photoshop is known to sometimes produce megabytes-large XMP metadata, which should be nuked from the orbit. And most of EXIF data (apart from Orientation) does not influence how the image appears on screen, so it's mostly safe to remove EXIF without affecting appearance. Users may also want to remove EXIF for privacy in order to remove potential GPS coordinates.

OTOH if the ICC profile is significantly different from sRGB, then its removal affects how the image is rendered in profile-aware viewers.

So an option to "remove everything except ICC" is 90% correct and relatively easy to implement.

Ideally it should be "remove everything except EXIF Orientation tag and non-sRGB ICC", but that requires editing EXIF and parsing ICC, so the bar is much higher.

kornelski avatar Jul 13 '21 15:07 kornelski

The JPEG data does not change when you discard the ICC profile, so it is incorrect and hyperbolic to use words such as "destructive" or "lossy" to describe this.

This is true, but users are not looking at the data, they are looking at images. And those may look widely incorrect when the metadata describing their correct look is removed. So from a users’ POV, this is destructive. Hyperbolic? Sure, too ;-)

megabytes-large XMP metadata

More and more, capture devices tend to also store eg. “secondary” images (eg. depth maps) in XMP in binary form. They weigh megabytes.

paperboyo avatar Jul 13 '21 16:07 paperboyo

This is true, but users are not looking at the data, they are looking at images. And those may look widely incorrect when the metadata describing their correct look is removed. So from a users’ POV, this is destructive. Hyperbolic? Sure, too ;-)

No, because by that same argument, displaying the image (even with an ICC profile) on an uncalibrated monitor would also be "destructive." That is not what the word "destructive" means, nor is it what the word "lossy" means. It is fair to say that the image is displayed "incorrectly" without an ICC profile.

Regardless, the suggested feature has been implemented upstream. Please test it.

dcommander avatar Jul 13 '21 17:07 dcommander