Alpha channel gets removed from grayscale image with IM 7.x

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
slgaficon
Posts: 10
Joined: 2019-02-18T01:15:47-07:00
Authentication code: 1152

Alpha channel gets removed from grayscale image with IM 7.x

Post by slgaficon »

I recently needed to upgrade from IM 6.7 to IM 7.x and ran into trouble with grayscale images. Precisely, I have a PSD file with alpha channel and clipping path which converted well with the existing generic script. But now, using the very same script, the alpha channel is removed.

Command line:
magick convert -units PixelsPerInch in.psd[0] -units PixelsPerInch -type TrueColor -depth 8 -density 300 -unsharp 0.0x0.0+0.0+0.0 +profile 8bim -alpha off out.psd

I tried several variations of the script but the alpha channel stays removed in the output image. Any ideas?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by fmw42 »

First, In IM 7 use magick, not magick convert. Can you post your PSD file so that we can see it and investigate? What is your exact version of ImageMagick 7.x.x.x and date of version and platform?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by snibgo »

I don't understand the problem. The command has "-alpha off". This removes the alpha channel. Why is this a problem?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by fmw42 »

Also why do an unsharp masking with all zero values?
slgaficon
Posts: 10
Joined: 2019-02-18T01:15:47-07:00
Authentication code: 1152

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by slgaficon »

To your last comment: You are absolutely right, the unsharp mask is worth nothing.
The command line given is the result of a longer script that generates it - with some overhead.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by fmw42 »

try

-type TrueColorAlpha

Or leave -type TrueColor out, since if your input is color with alpha, then your output should also be.

Please always provide your full IM version and platform when asking questions, since syntax may vary. Also provide your input image if possible.
slgaficon
Posts: 10
Joined: 2019-02-18T01:15:47-07:00
Authentication code: 1152

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by slgaficon »

IM Version: 7.0.8-27 Q16 x64
Platform Windows x64

I changed the command to:
magick convert -units PixelsPerInch 5845394_02_1c_DE.psd[0] -units PixelsPerInch -depth 8 -density 300 +profile 8bim converted/5845394_02_1c_DE.psd

PhotoShop cannot read the created psd file: ... file is not compatiple with this version of PhotoShop.

Next, using TrueColorAlpha:
magick convert -units PixelsPerInch 5845394_02_1c_DE.psd[0] -units PixelsPerInch -type TrueColorAlpha -depth 8 -density 300 +profile 8bim converted/5845394_02_1c_DE.psd

PSD is readlable but has no alpha channel.

What is wrong?
slgaficon
Posts: 10
Joined: 2019-02-18T01:15:47-07:00
Authentication code: 1152

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by slgaficon »

Original file available here: http://nas.gaficon.de/sharing/V21Fgfu3c
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by fmw42 »

This command works fine for me on IM 7.0.8.33 Q16 Mac OSX. As I said above, do not use magick convert. Use simply magick. Adding [0] prevents imagemagick from accessing the background alpha. So I removed it.

Code: Select all

magick 5845394_02_1c_DE.psd +profile 8bim -depth 8 -units PixelsPerInch -density 300 -type TrueColorAlpha 5845394_02_1c_DE_fred.psd
slgaficon
Posts: 10
Joined: 2019-02-18T01:15:47-07:00
Authentication code: 1152

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by slgaficon »

Thanks, using your recommendations, I do get a transparent image. Next step after conversion is to draw a shadow.
With ImageMagick 6 and the cited command, the shadow was drawn around the object. Now, the shadow is drawn at the border of the canvas.

This seems to be because the apha channel is no longer explicitely present (PhotoShop only shows Greyscale channel)

IM command parameter: magick .\converted\5845394_02_1c_DE.psd[0] -resize 1500x1500> -colorspace sRGB ( +clone -background rgb(68,68,68) -shadow 100x8.0+5+5 ) +swap -background white -layers merge +repage ( -strip -gravity center -crop 1524x1523+0+0 +repage -resize 1500x1499 -density 72 -extent 1500x1499 ) .\converted\shadow\5845394_02_1c_DE.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by snibgo »

Fred removed [0] because that image has no alpha.

You replaced [0], and get an image with no alpha.

So, try removing [0], or use [1] instead, or whatever.
snibgo's IM pages: im.snibgo.com
slgaficon
Posts: 10
Joined: 2019-02-18T01:15:47-07:00
Authentication code: 1152

Re: Alpha channel gets removed from grayscale image with IM 7.x

Post by slgaficon »

Thanks for reply. Leaving out [0] everywhere solves the issue.
Can anyone tell me why this worked in previous IM Versions? Is it a general recommendation to leave out [0]?
Post Reply