Using Imagemagick to batch split png RGBA channels, then recombine as a layered PSD

Viewed 571

I need to separate the RGBA channels of a batch of png images and save the separated channels in a layered PSD. I've been doing this in GIMP, using the decompose colours function and then exporting as PSD, but this is a lot of clicks per image.

I've been trying to automate the process using Imagemagick. After lots of Googling I've made some progress but I'm a bit stuck. Currently I'm using this command:

FOR /R %a IN (*.png) DO magick convert "%~a" -channel ALL -separate "%~dpna.jpg"

This gives me four jpg images per png (one per colour channel). So far so good. I just need to save the colour channels as layers in psd. One for each of the original images.

I've tried just changing the save format to .psd, like this:

FOR /R %a IN (*.png) DO magick convert "%~a" -channel ALL -separate "%~dpna.psd"

This gives me a layered PSD file, with only three layers: Alpha, and two other greyscale layers that I think are B and G (R missing), but I'm not 100% sure - the original images don't have much colour data in them.

So just to restate - I need to split the RGBA channels of a png, then recombine them as layers in a psd. I need to batch process this over dozens of png images.

Any insight on this would be really appreciated.

1 Answers

I do not think you can do all that you want in ImageMagick. I have not been able to add transparency to the PSD file.

I am using ImageMagick 6.9.11.34 Q16 on Mac OSX Sierra

You can process an opaque RGB file and get your layered PSD:

convert logo: -transparent white logot.png
convert logot.png \( -clone 0 -channel rgb -separate +channel \) \( -clone 0 -alpha extract \) -type truecolor logot.psd

Or you can process RGBA, but A will be just another layer:
convert logo: -transparent white logot.png
convert logot.png \( -clone 0 -channel rgba -separate +channel \) -type truecolor logot.psd

But to add transparency, you have to do that differently and it does not work for PSD

convert logo: -transparent white logot.png
convert logot.png \( -clone 0 -channel rgb -separate +channel -type truecolor \) logot.psd
convert logot.png -alpha extract alpha.png
convert logot.psd alpha.png -alpha off -compose copy_opacity -composite logot.psd
Related