Convert to PSD forcing RGB to grayscale

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
petitbas
Posts: 5
Joined: 2014-09-24T16:50:16-07:00
Authentication code: 6789

Convert to PSD forcing RGB to grayscale

Post by petitbas »

I'm trying to convert an all black frame with data only in the alpha channel. When I try this command:

Code: Select all

convert tmpkb1Es2.png temp.psd
The resulting file ends up with grayscale data in the R channel, no data in the G or B channel and a proper alpha channel. Running identify gives me this:

Code: Select all

identify temp.psd 
temp.psd[0] PSD 2940x1302 2940x1302+0+0 8-bit Grayscale Gray 256c 15.31MB 0.000u 0:00.009
temp.psd[1] PSD 2940x1302 2940x1302+0+0 8-bit Grayscale Gray 256c 15.31MB 0.000u 0:00.000
I've tried -type TrueColorMatte, -def psd:color-type=6, nothing seems to help in generating a true RGB image with data in R G and B channels. Any ideas?

My sample file is here:
https://www.dropbox.com/s/xzn670oxmdo2t ... 2.png?dl=0

This is using ImageMagick 6.8.9-7
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert to PSD forcing RGB to grayscale

Post by fmw42 »

I do not think you ca make a grayscale image into RGB in IM unless the data is different in each channel. IM and other tools will recognize that the data is the same in each channel and set the colorspace to gray, if that format supports gray.

I tried

Code: Select all

convert tmpkb1Es2.png -type truecoloralpha tmpkb1Es2d.psd
but that did not work. I also tried to assign an sRGB profile, but PS would not accept it and says it is invalid (for a grayscale image)

You will have to open the png or psd file in PS (or perhaps GIMP) and change the colorspace there.

Perhaps someone else knows a way that I do not.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Convert to PSD forcing RGB to grayscale

Post by glennrp »

fmw42 wrote:I do not think you can make a grayscale image into RGB in IM unless the data is different in each channel. IM and other tools will recognize that the data is the same in each channel and set the colorspace to gray, if that format supports gray.
Perhaps someone else knows a way that I do not.
Adding a non-gray background color causes the PNG encoder to write an otherwise all-gray image as RGB. I don't know if that works for other output formats though.
petitbas
Posts: 5
Joined: 2014-09-24T16:50:16-07:00
Authentication code: 6789

Re: Convert to PSD forcing RGB to grayscale

Post by petitbas »

glennrp wrote:
fmw42 wrote:I do not think you can make a grayscale image into RGB in IM unless the data is different in each channel. IM and other tools will recognize that the data is the same in each channel and set the colorspace to gray, if that format supports gray.
Perhaps someone else knows a way that I do not.
Adding a non-gray background color causes the PNG encoder to write an otherwise all-gray image as RGB. I don't know if that works for other output formats though.
How do you add a non-gray background?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Convert to PSD forcing RGB to grayscale

Post by glennrp »

petitbas wrote:How do you add a non-gray background?

Code: Select all

convert input.png -background "#112233" output.png
petitbas
Posts: 5
Joined: 2014-09-24T16:50:16-07:00
Authentication code: 6789

Re: Convert to PSD forcing RGB to grayscale

Post by petitbas »

glennrp wrote:
petitbas wrote:How do you add a non-gray background?

Code: Select all

convert input.png -background "#112233" output.png
Hmmm, given that command and an all black "input.png" save for its alpha channel, the result is a grayscale image.

Same thing when I try something like:

Code: Select all

convert bg.png shadow.png fg.png final.psd
bg.png and fg.png are both RGBA images with data in all channels.
shadow.png is completely black in the RGB channels, only has data in alpha channel.

The result is a psd with multiple layers that have RGBA data in them, except for the "shadow.png" layer, that one only data in the R and A channels, nothing in G or B channels. Is there a way to force copy of channel data to other channels if they're empty?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Convert to PSD forcing RGB to grayscale

Post by glennrp »

Try this:

Code: Select all

convert tmpkb1Es2png -channel A -negate -separate gray.psd
Tested with IM-6.8.9-8 on Ubuntu.
petitbas
Posts: 5
Joined: 2014-09-24T16:50:16-07:00
Authentication code: 6789

Re: Convert to PSD forcing RGB to grayscale

Post by petitbas »

glennrp wrote:Try this:

Code: Select all

convert tmpkb1Es2png -channel A -negate -separate gray.psd
Tested with IM-6.8.9-8 on Ubuntu.
Sorry, I just reread the subject of this thread and it's misleading. It should have read "Convert to PSD is forcing RGB to grayscale, how can I avoid this?".

Your command works great, but it's converting to RGB to grayscale. I'm actually trying to force all channels to be exported as black RGB while keeping the alpha from the image and save that as a .PSD.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert to PSD forcing RGB to grayscale

Post by fmw42 »

You did not post an RGB PSD image. It was simply grayscale PNG.
petitbas
Posts: 5
Joined: 2014-09-24T16:50:16-07:00
Authentication code: 6789

Re: Convert to PSD forcing RGB to grayscale

Post by petitbas »

fmw42 wrote:You did not post an RGB PSD image. It was simply grayscale PNG.
Actually, when I run:

Code: Select all

identify tmpkb1Es2.png
I get this result:

Code: Select all

/Users/chris/Dropbox/tmpkb1Es2.png PNG 2940x1302 2940x1302+0+0 8-bit sRGB 218KB 0.010u 0:00.000
So I believe ImageMagick thinks it's an RGB file (admittedly with the same data in all three channels). I know IM will convert that image down to grayscale for memory efficiency but when the file is written out as a PSD and I open it in Photoshop, the file is now a grayscale image that doesn't display properly with an alpha channel.

So the question is, even if IM determines the most efficient way of handling the image is as a grayscale, how can I force it to write RGB channels to a PSD file.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert to PSD forcing RGB to grayscale

Post by fmw42 »

I am not sure why identify says it is sRGB. If you use identify -verbose you will see it is grayscale

Code: Select all

Image: tmpkb1Es2.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 2940x1302+0+0
  Units: Undefined
  Type: Bilevel
  Base type: Bilevel
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8-bit
  Channel depth:
    gray: 1-bit
    alpha: 8-bit
IM will not convert a grayscale image to RGB unless you change at least one pixel in the image to color or unless the output format does not support grayscale. You will have to change the colorspace in Photoshop.
Post Reply