colorspace forced to Gray if pixels are all grayscale

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Locked
jaciones@gmail.com
Posts: 4
Joined: 2015-12-21T14:48:38-07:00
Authentication code: 1151

colorspace forced to Gray if pixels are all grayscale

Post by jaciones@gmail.com »

Ubuntu 18.04

> convert --version
Version: ImageMagick 6.9.11-6 Q16 x86_64 2020-04-16 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC OpenMP(3.1)
Delegates (built-in): fftw fontconfig freetype jbig jng jpeg lcms lzma openexr pangocairo png tiff webp x xml zlib

> convert -size 100x100 -set colorspace sRGB -colorspace sRGB canvas:#ffffff /tmp/test.png

identify -format %[colorspace] /tmp/test.png
> 'Gray'

We have recently updated from ImageMagick 6.9.9-36 and this breaks a bunch of our compositing functionality.

This is a problem because if you want to create a white canvas and composite something on top, the output is monochrome because the colorspace is 'Gray' and not the expected 'sRGB'.

The only workaround I have been able to find is to output as .mpc file and use that as a source for compositing. But this seems like a bug, am I wrong?

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

Re: colorspace forced to Gray if pixels are all grayscale

Post by fmw42 »

use PNG24:test.png for output

jaciones@gmail.com
Posts: 4
Joined: 2015-12-21T14:48:38-07:00
Authentication code: 1151

Re: colorspace forced to Gray if pixels are all grayscale

Post by jaciones@gmail.com »

Thanks for the additional workaround, but what if I wanted to use a JPG? Same problem. This feels like a bug no? Is this a new feature?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: colorspace forced to Gray if pixels are all grayscale

Post by snibgo »

For JPG, use "-type truecolor" to force 3-channel JPEGs.

IM has always tried to minimize output filesizes, eg by recognizing when all pixels are gray, so only one channel is neeed. But IM's methods for doing this have changed.
snibgo's IM pages: im.snibgo.com

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

Re: colorspace forced to Gray if pixels are all grayscale

Post by fmw42 »

-define colorspace:auto-grayscale=on|off prevent automatic conversion to grayscale inside coders that support grayscale. This should be accompanied by -type truecolor. PNG and TIF do not need this define. With PNG, just use PNG24:image. With TIF, just use -type truecolor. JPG and PSD will need this define.
See https://imagemagick.org/script/command- ... php#define

Locked