-
Hello everyone, I've been trying to export a .tiff file to have multiple Alpha channels. I need 1 to be (un)associated and 1 to be unspecified. I am able to generate this through photoshop so I know it's possible, but I haven't been able to do it through code. How would I go about doing this? |
Beta Was this translation helpful? Give feedback.
Replies: 22 comments 9 replies
-
What version of IM, on what platform? I assume you also want three colour channels (R,G,B). Images in ImageMagick have only one alpha channel, but can also have meta-channels. Here is one method to do what you want. Write the pixel values to a text file that I name
Both lines must have a new-line, either "\n" (as usual for unix) or "\r\n" (as usual for Windows). The file has x and y coordinates, a colon, then five values. This example has only two pixels, for an image that is size 1x2. Read this with IM, and write a TIFF, like this:
tiffinfo than says this about the TIFF file:
As required, the file has 5 channels. 3 are for RGB, and the extra samples are "unassoc-alpha" and "unspecified". IM can read the TIFF file, and write ftxt:
The values in parentheses are shown on a scale of 0 to QuantumRange. For more details about "ftxt:", see ftxt: formatted text. |
Beta Was this translation helpful? Give feedback.
-
Where does the data for your fifth channel come from? Is it simply a copy of the alpha channel? That seems pointless. Doesn't that data come from a different image? |
Beta Was this translation helpful? Give feedback.
-
Please answer my questions: what version of IM are you using? On what platform (bash, Windows, whatever)? The screenshot you show is of an image that seems to have just one alpha channel. Please link to a file that contains five channels, as you want them. Link to the actual file, not a screenshot of some program that is displaying the file. It would help if you also linked to a sample input file. |
Beta Was this translation helpful? Give feedback.
-
I know nothing about JS. I will show Windows syntax commands, and will leave any translation to JS to you. The ImageMagick version number is something like 6.9.9-10 or 7.1.0-49. I suppose your "IM 0.1.3" is something different. What is the complete text output from "magick -version"? I have named your input file Copying alpha to a meta channel, and writing the result to a TIFF, should be simple and fast:
Sadly, this doesn't create a meta channel, so out.tiff contains just RGBA. I don't know why there is a problem. Perhaps there is a bug in IM, or in my brain. The job can be done via "ftxt:", but it is slow and complex. First, we write pixel values to text files:
The "-write info:" tells us the size:
We need the size later. The first few lines of out1.txt are:
It also has lines like this:
I use Windows, so newlines are "\r\n". This would cause problems for the
Now we use the
The first few lines of out3.txt are:
It has 5 channels, so we can read it with IM, and write a TIFF, as I showed above. Note the size must match what we found earlier.
tiffinfo confirms that x.tiff has:
Note: tr, paste and tiffinfo are utilities commonly available, eg from Cygwin for Windows. |
Beta Was this translation helpful? Give feedback.
-
Note that a bug in "
... will now work.
Do you want the clipping path in the result as a metadata vector path, or as an alpha channel? IM can copy metadata vector path from one file to another. If you are combining two or more files in a " If you want the clipping path as an alpha channel, then that is simple -- you are simply combining raster images.
I suggest you link to the input files and explain what result you want. |
Beta Was this translation helpful? Give feedback.
-
The file there is named
You want an output with the path from
|
Beta Was this translation helpful? Give feedback.
-
I'm still stuck on this issue, so far we've managed to generate a .tiff file with 2 alpha channels (showing up correctly in photoshop). |
Beta Was this translation helpful? Give feedback.
-
What are your input files? Which contains the clipping path? What command have you tried? |
Beta Was this translation helpful? Give feedback.
-
Downloads.zip |
Beta Was this translation helpful? Give feedback.
-
None of the other files contain a path. |
Beta Was this translation helpful? Give feedback.
-
Yes that's the output I want. It seems one of the files lost it's path. so this it my current output, containing only a single alpha channel but containing a path. |
Beta Was this translation helpful? Give feedback.
-
Okay, What else do you want in your output file? Your |
Beta Was this translation helpful? Give feedback.
-
Generally it's just a duplicate from the alpha channel that already exists (see Imagine as if I would duplicate the Alpha channel of So I have to either move the path from the gimp exported image to the image with the alpha AND the meta channel or copy the Alpha channel of the image with the path to it's meta channel. I've tried the thing you mentioned before like: I also don't see the 2183x2137 image you mentioned in |
Beta Was this translation helpful? Give feedback.
-
This post addresses " Using IM v7.1.0-54 downloaded today, "
Exiftool says:
So x.tiff has nine channels. Oops. "
Hmm. We asked for one meta channel but have five. The meta channels seem to contain the same data as each other, but different to the alpha channel. We get the same result when we directly ...
So IM still doesn't process We get a similar problem with So, to copy the alpha channel into a new meta channel, I suggest the "ftxt:" method I detailed above. (Incidentally, the IM language needs a mechanism to specify which meta channel we want, in " |
Beta Was this translation helpful? Give feedback.
-
I've ran into this issue trying to copy to the meta channel as well, maybe something to report as a possible bug? Copying the alpha channel using ftxt works but I don't know yet how to keep the additional data like the clipping-path while doing that, hence my problem sadly enough. |
Beta Was this translation helpful? Give feedback.
-
To copy alpha to a new meta channel, this Windows BAT script (named
To copy all the Photoshop paths from one file (eg in.jpg) to another (eg out.tiff), where the output file already exists:
The file
|
Beta Was this translation helpful? Give feedback.
-
Perfect, thanks a lot! Using the exiftool command I managed to create an image having 2 alpha channels and the path I needed. I only have 1 small issue remaining. Currently the ExtraSamples property gets denoted as I've tried swapping the channels using |
Beta Was this translation helpful? Give feedback.
-
I don't think that is possible in IM. The first "ExtraSample" is what IM calls "alpha". That can be set to one of: 0 = Unspecified data For example, use " The second "ExtraSample" is what IM calls a meta-channel. IM has no mechanism for setting a meta-channel to unspecified, associated or unassociated. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick reply, you've already helped a lot by letting me get this result so far. It's a shame this seems to be at the limit of IM, I imagine the FTXT might've allowed to save channel data in a prespecified order or the sort. Would you by chance know any other software I could look into to achieve this goal? |
Beta Was this translation helpful? Give feedback.
-
When IM reads a
You might look at G'MIC (http://gmic.eu/), where "channel" is just another dimension, like "width" and "height". It is very easy to add new channels to an image. Thousands of channels if you want (and have enough memory). But I don't know if G'MIC can write those channels to a TIFF in the way you want. |
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, " |
Beta Was this translation helpful? Give feedback.
-
I figured out how to have the alpha layers in the way I want it. I create a "template" file manually in photoshop, in this file I create the channels in the way I want it (transparency in the RGB and a separate alpha channel named "Alpha 1". I export this while having "save transparency" ticked. This will generate a file holding the photoshop tags I need (Alpha Channel Names). So instead of trying to add the tags later someway, I figured out I can use photoshop to make one and in a way copy them to my end-file. Then in my processing process, I move the channel data of the 5 channel image I generated using the FTXT code you gave me above to a copy of my previously created template file. Then after this I move my path from another image to put it all together. In the end I had to use a combination of GIMP, ImageMagick and ExifTool. Thank you for the continued support @snibgo, I managed to get the result I needed due to a big part of your help. |
Beta Was this translation helpful? Give feedback.
To copy alpha to a new meta channel, this Windows BAT script (named
alpha2meta.bat
) does the job: