How to ignore alpha channel?

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
cmcfarling
Posts: 14
Joined: 2003-12-23T12:39:53-07:00

How to ignore alpha channel?

Post by cmcfarling »

I need to convert a CMYK TIFF that contains an alpha channel to JPEG. My original command was

Code: Select all

convert -resample 72x72 -resize "1024x1024>" -units PixelsPerInch -quality 95 test.tif test.jpg
I've used this for a while on images that do not contain an alpha channel with no problems. However if the TIFF contains an alpha channel then the output file has unsmooth, pixelated edges. Here are some samples:

orig: http://www.50amp.com/im/alphatest.tif
what it should look like: http://www.50amp.com/im/alphatest-good.jpg
what it shouldn't look like: http://www.50amp.com/im/alphatest-bad.jpg

I've tried several options to try to keep IM from interpreting the alpha channel but have had no luck. For example:

Code: Select all

convert -resample 72x72 -resize "1024x1024>" -units PixelsPerInch -quality 95 test.tif -alpha off test.jpg
This gives the same bad result. Shouldn't 'alpha off' force IM to ignore the alpha channel?

Code: Select all

convert -channel CMYK -resample 72x72 -resize "1024x1024>" -units PixelsPerInch -quality 95 test.tif test.jpg
I tried this in an effort to force IM to operate only on the CMYK channels however this produces the same bad result.

Am I making syntax errors or do these operators just no do what I'm thinking they do?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to ignore alpha channel?

Post by anthony »

You have to remove the transparency, generally but 'flattening' the image onto soem background color.

See IM Examples, Common File Formats, JPEG transparency - NOT
http://www.imagemagick.org/Usage/formats/#jpg_trans
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cmcfarling
Posts: 14
Joined: 2003-12-23T12:39:53-07:00

Re: How to ignore alpha channel?

Post by cmcfarling »

The -flatten operator seems to work in this case. I'm still curious why the -alpha Off operator wouldn't accomplish this. A command such as -channel CMYK also seems like it should accomplish this. Based on the documentation it seems that either of these operators should do something in this case, however neither have an effect. If anyone cares to elaborate I'd like to hear.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to ignore alpha channel?

Post by anthony »

alpha off removes transparency, but does not specify what the transparency should be replaced with. It may be randome garbage. That is hidden fully-transparent colors left over from image building and masking.

better to flatten or border the image to overlay it onto some solid color background.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply