montage does not seem to honor "-strip"

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

montage does not seem to honor "-strip"

Post by sas »

Even with the "-strip" option, "montage" outputs a PNG with a redundant gAMA chunk:

Code: Select all

$  montage rose: -strip PNG:- | identify -verbose - | grep 'png:'                  
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45454544 (See Gamma, above)
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 2
    png:IHDR.color_type: 2 (Truecolor)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 128, 126
    png:sRGB: intent=0 (Perceptual Intent)
"convert" on the other hand, does not output the redundant gAMA chunk when the "-strip" option is used:

Code: Select all

$  convert rose: -strip PNG:- | identify -verbose - | grep 'png:'
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 2
    png:IHDR.color_type: 2 (Truecolor)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 70, 46
    png:sRGB: intent=0 (Perceptual Intent)
How can I get montage to respect "-strip" just like convert does?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: montage does not seem to honor "-strip"

Post by fmw42 »

Pipe your montage output to convert and do the strip there
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

Re: montage does not seem to honor "-strip"

Post by sas »

That works, thanks.

But why does "montage -strip" not do it it in the first place? Is it a bug? The montage option summary does list -strip as a supported option.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: montage does not seem to honor "-strip"

Post by fmw42 »

I do not know. But why do you think the gamma chuck in redundant? Does it hurt to keep it? I would think it best to have that there so that PNG readers will know what gamma it has.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: montage does not seem to honor "-strip"

Post by glennrp »

The gAMA chunk is redundant when the sRGB chunk is present.
-strip should also be removing the cHRM chunk. I'll see about fixing that.

The documentation says about the -strip option:
strip the image of any profiles or comments.

It's debatable whether the PNG gAMA, cHRM, and sRGB chunks are profiles. I think they are,
and -strip should be removing them all. The fix is to add gAMA and cHRM to the list of chunks in
magick/image.c" line 3514
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

Re: montage does not seem to honor "-strip"

Post by sas »

fmw42 wrote:why do you think the gamma chuck in redundant?
Like the "-define" documentation says:
"As a special case, if the sRGB chunk is excluded and the gAMA chunk is included, the gAMA chunk will only be written if gamma is not 1/2.2, since most decoders assume sRGB and gamma=1/2.2 when no colorspace information is included in the PNG file.
[...]
The -strip option does the equivalent of the following for PNG output:
-define png:exclude-chunk=EXIF,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date
"

That is, stripping a gAMA of 0.45454544 should be fine because well-behaved PNG readers will assume it's sRGB anyway.
fmw42 wrote:Does it hurt to keep it? I would think it best to have that there so that PNG readers will know what gamma it has.
It depends on where the images will be used. In my case, they'll be part of a website.

And the problem is that modern browsers like Firefox are not well-behaved in the aforementioned sense: They display the colors of PNGs with a 0.45454544 gAMA chunk differently from everything else - where everything else includes colors from CSS style sheets, or stripped PNGs, or from other image formats, etc.

So one is better off stripping 0.45454544 gAMA chunks from PNGs that will be part of a website, so that any #rrggbb color in the image looks identical to the same #rrggbb color in surrounding page elements. The color may look "wrong" (i.e. not properly color-corrected), but at least this way all page elements will be rendered equally wrong.
Last edited by sas on 2016-01-01T13:16:37-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: montage does not seem to honor "-strip"

Post by fmw42 »

Thanks for the explanation. The IM developers will need to look into this. You can post a note to the Bugs forum with a link back here to your post above. Please include your IM version and platform.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: montage does not seem to honor "-strip"

Post by fmw42 »

This seems to work on IM 6.9.2.10 Q16 Mac OSX

Code: Select all

montage rose: -define png:exclude-chunk=gAMA -tile 1x1 -geometry +0+0 rose.png
identify -verbose rose.png

Code: Select all

  Properties:
    date:create: 2016-01-01T12:37:48-08:00
    date:modify: 2016-01-01T12:37:48-08:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 2
    png:IHDR.color_type: 2 (Truecolor)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 70, 46
    png:sRGB: intent=0 (Perceptual Intent)
    signature: a698f2fe0c6c31f83d19554a6ec02bac79c961dd9a87e7ed217752e75eb615d7
see define at http://www.imagemagick.org/script/comma ... php#define
Post Reply