Page 1 of 1
TIFF with alpha channels, -alpha remove
Posted: 2013-03-07T12:09:36-07:00
by axelrose
Hello all,
can anyone guide me with a TIFF alpha channel/path question.
I need to convert all sorts of TIFFs to a normalized JPEG. Some of those TIFFs
have extra alpha channels (sample "logo-alpha.tif", presumably a left over from
the designer), some have transparent background and a clipping path (sample
"logo-path.tif").
I'm looking for a generic convert command line which processes both while
filling the transparency with a defined background color.
Currently I do
Code: Select all
convert input.tif -background yellow -alpha remove output.jpg
The results are:
input1:
http://dl.dropbox.com/u/84530/IM/logo-alpha.tif
output1:
input2:
http://dl.dropbox.com/u/84530/IM/logo-path.tif
output2:
output1 should not have any yellow patches. The extra channels should
be ignored. output2 is correct.
An ideal solution would use the same convert command for both input
files. output1 should not be influenced by the extra alpha channels but output2
must be on a yellow background. I wouldn't like to do the extra step of
recognizing whether the input has a clipping path included.
Thanks very much for any help
Axel
(using IM 6.8.3-3 with tiff 3.9.7)
Re: TIFF with alpha channels, -alpha remove
Posted: 2013-03-07T14:27:34-07:00
by fmw42
Your first tiff image shows two alpha channels in PS, one is the cross shape and the other is an oval. I do not see any paths shown in PS.
IM can only work with one alpha channel and takes the first only. Thus you get the cross shaped image with the rest background yellow with your command.
IM does not see any clip paths. I tried:
convert logo-alpha.tif -alpha transparent -clip -alpha opaque -strip 1tmp1.jpg
convert: no clip path defined `logo-alpha.tif': No such file or directory @ error/image.c/ClipImagePath/719.
see
http://www.imagemagick.org/Usage/masking/#clip
Your second image has both an background transparency and a clip path. That is why it works.
Open your images in Photoshop and compare them in the channel mode and path mode them.
Re: TIFF with alpha channels, -alpha remove
Posted: 2013-03-07T14:36:32-07:00
by axelrose
Thanks for checking this.
input1 has to alpha channels, true. But it could have only one or even more. That is not my concern.
Let me rephrase:
I want to use "-alpha remove" for all TIFF images since this is only way I know to get a good
preview from a TIFF with transparency and clip path. But if I do this those other TIFFs with
alpha channels don't look as intended.
Do I need to check first if an image has a clipping path and use "-alpha remove" only then?
Or can I use something else which works for both inputs?
Cheers, Axel.
Re: TIFF with alpha channels, -alpha remove
Posted: 2013-03-07T17:17:14-07:00
by fmw42
I am not an expert on TIFF. But from what I know, your second example got its yellow from the background transparency rather than the clip path.
If you use -strip that will remove the path (8BIM profile).
convert logo-path.tif -strip -verbose info:
So to process your second image without the path 8BIM profile,
convert logo-path.tif -strip -background yellow -alpha remove show:
which works just fine
To process your second image with the path and not the background transparency,
convert logo-path.tif -alpha set -background yellow -alpha background -clip -alpha off -strip show:
Note that -alpha set only removes alpha channels. It still leaves the background transparency, but the command above just processes from the (clip) path.
So the bottom line:
1) You can test if an alpha channel/background transparency or for a clip path from looking at the verbose information for the file. If there is an alpha channel or background transparency, it will show alpha channel data (or the type will include alpha in the name). If there is a clip path, it will show an 8BIM tiff profile
2) You will not have any control over which alpha channel is to be used by IM.
3) You can look for a clip path first and use the clip command above
4) If no clip path, then use whatever alpha channel IM allows you to use using your original command. My guess is that it will take a true alpha channel over the background transparency. But if there are more than one alpha channel, then you will likely get the first one.
I will defer to any one who knows otherwise about the above.
IM 7 will have more smarts regarding alpha channels and you may then be able to choose which alpha channel to use (or background transparency)
Re: TIFF with alpha channels, -alpha remove
Posted: 2013-03-08T01:00:19-07:00
by axelrose
Thanks again for using so much effort on my question.
You got me wrong though.
The second example is fine for me.
It is the first example which bugs me. I want IM to ignore those extra
channels of the TIFF file. They shouldn't be considered for transparency.
If I save both TIFF files as PSD and use "-alpha remove" the result is what I want!
input1 as psd:
http://dl.dropbox.com/u/84530/IM/logo-alpha.psd
output1 (from "convert logo-alpha.psd[0] -background yellow logo-alpha.psd.jpg"):
input2 as psd:
http://dl.dropbox.com/u/84530/IM/logo-path.psd
output2 (from "convert logo-path.psd[0] -background yellow logo-path.psd.jpg"):
In short:
If using "-alpha remove" on TIFF files how could I prevent interpretation of
extra channels as transparency source.
Best, Axel.
Re: TIFF with alpha channels, -alpha remove
Posted: 2013-03-08T10:14:01-07:00
by fmw42
If I save both TIFF files as PSD and use "-alpha remove" the result is what I want!
Your tiff input 1 does not have either a path or background transparency. So there is no way to remove the alpha channels and get what you want unless there is a path and there is no path.
Your PSD file for input 1 does not work to produce yellow background for me, because it does not have either background transparency or a path either.
You if you got it to work using -alpha remove, I cannot reproduce that for input 1 in either tiff or psd
Re: TIFF with alpha channels, -alpha remove
Posted: 2013-03-08T11:24:48-07:00
by axelrose
Your tiff input 1 does not have either a path or background transparency. So there is no way to remove the alpha channels and get what you want unless there is a path and there is no path.
Correct. We're getting closer to my problem now.
I have a bag full of TIFF files and do not like to check with an extra command whether they contain a path or not.
If they contain a path - I want to clip by using the "-alpha remove" option.
If they do not contain a path - I hope for a command which does path containing TIFF files equally well
as those which do not contain a path.
Currently I'm unsure what is correct for input1, a TIFF with extra channels.
Are those channels to be considered as alpha channels creating transparency
or can they be ignored. How can I ignore them?
Best, Axel.
Re: TIFF with alpha channels, -alpha remove
Posted: 2013-03-08T11:36:36-07:00
by fmw42
Currently I'm unsure what is correct for input1, a TIFF with extra channels.
Are those channels to be considered as alpha channels creating transparency
or can they be ignored. How can I ignore them?
It is not an IM problem, but a problem with your tiff files. The first one has no background transparency and no path. So if you ignore the two alpha channels, you will not have anything to go by to color the background. That is why it does not work.
You can certainly ignore the alpha channels by using -alpha off or -alpha remove, but that will not help, since then you have no outline in any form.
The only hope you have is that the first alpha channel contains a mask that is the same as what you want from a path. But your first file does not conform. The two alpha channels have totally inconsistent mask for what you want. (One is a cross and the other is an ellipse. Neither are the outline)
You need either a clip path, a background transparency showing the same outline as a mask, or a true alpha channel showing the same outline as a mask. There are no other options to automatically form that mask.