Discussion:
[GM-help] Preventing -extent from converting to RGB
Toby Thain
2016-08-28 00:43:45 UTC
Permalink
Hi,

I have a grey scale source image and I am applying a -rotate and an
-extent operation. I'm finding that the output is RGB, presumably
because of the background colour? Is there any way of getting the
equivalent of -extent without the RGB conversion? (I know I can add a
-channel to go back to greyscale, but it seems superfluous.)

Thanks
--Toby

------------------------------------------------------------------------------
g***@comcast.net
2016-08-28 01:36:42 UTC
Permalink
Post by Toby Thain
Hi,
I have a grey scale source image and I am applying a -rotate and an
-extent operation. I'm finding that the output is RGB, presumably
because of the background colour? Is there any way of getting the
equivalent of -extent without the RGB conversion? (I know I can add a
-channel to go back to greyscale, but it seems superfluous.)
Did you try making the background a grayscale colour?

Glenn

------------------------------------------------------------------------------
Toby Thain
2016-08-28 02:29:58 UTC
Permalink
Post by g***@comcast.net
Post by Toby Thain
Hi,
I have a grey scale source image and I am applying a -rotate and an
-extent operation. I'm finding that the output is RGB, presumably
because of the background colour? Is there any way of getting the
equivalent of -extent without the RGB conversion? (I know I can add a
-channel to go back to greyscale, but it seems superfluous.)
Did you try making the background a grayscale colour?
That was my first thought too, but the doc only talks about RGB colours;
there was no obvious way to specify a single channel "colour." (Of
course there may be a way I missed.)

--Toby
Post by g***@comcast.net
Glenn
------------------------------------------------------------------------------
_______________________________________________
Graphicsmagick-help mailing list
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-help
------------------------------------------------------------------------------
g***@comcast.net
2016-08-28 08:24:33 UTC
Permalink
Post by Toby Thain
Post by g***@comcast.net
Post by Toby Thain
Hi,
I have a grey scale source image and I am applying a -rotate and an
-extent operation. I'm finding that the output is RGB, presumably
because of the background colour? Is there any way of getting the
equivalent of -extent without the RGB conversion? (I know I can add a
-channel to go back to greyscale, but it seems superfluous.)
Did you try making the background a grayscale colour?
That was my first thought too, but the doc only talks about RGB colours;
there was no obvious way to specify a single channel "colour." (Of
course there may be a way I missed.)
Try "-background white", "-background black", "-background '#a0a0a0'",
etc. As long as all three components of the background color are
equal, it won't force GM to write an RGB image.

BTW I'm assuming you are writing a PNG, and working with the current
version of GM.

Glenn

------------------------------------------------------------------------------
Bob Friesenhahn
2016-08-28 14:01:11 UTC
Permalink
Post by g***@comcast.net
Post by Toby Thain
Post by g***@comcast.net
Did you try making the background a grayscale colour?
That was my first thought too, but the doc only talks about RGB colours;
there was no obvious way to specify a single channel "colour." (Of
course there may be a way I missed.)
Try "-background white", "-background black", "-background '#a0a0a0'",
etc. As long as all three components of the background color are
equal, it won't force GM to write an RGB image.
BTW I'm assuming you are writing a PNG, and working with the current
version of GM.
The ExtentImage() function is very simple. First it clones the input
image to a new image, then uses SetImage() to set the new image to the
specified background color using the specified opacity. Secondly, it
uses CompositeImage() to composite an image at the specified offsets
using the specified composition operator.

The use of CompositeImage() will promote the image to DirectClass type
and it is possible that SetImage() produces DirectClass type as well.

With some work is possible for the code to intuit when PseudoClass can
be used, and if the resulting image is grayscale. Some of this
intuiting may already be done. Otherwise a DirectClass image will be
produced.

Using '-type Optimize' may help by inspecting all the pixels to see if
they are grayscale, but this won't cause the image to be converted to
PseudoClass (colormapped). At one time, the PNG writer was making
special use of '-type Optimize' but I think that support was removed.

Bob
--
Bob Friesenhahn
***@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/

------------------------------------------------------------------------------
Loading...