Page 1 of 1

Batch Merge Alpha and RGB images together (same filenames - different extensions)

Posted: 2019-03-21T10:58:04-07:00
by Zeneric
I have thousands of Alpha (.tiff) and RGB (.png) images I need to merge together and output to .tga format with alpha channel.
This command works for merging 2 images into 1:

Code: Select all

magick convert "a.png" "a.tiff" -alpha off -compose CopyOpacity -composite "a.tga"
How do I batch it on thousands of images in subfolders and output to same source?

I tried this:

Code: Select all

for /r %g in (*) do magick convert "%g.png" "%g.tiff" -alpha off -compose CopyOpacity -composite "%g.tga"
It doesn't work/returns errors.

I think the problem is with (*). I need to replace that * with something else but don't know what. need %g to read/write filename without extension name.

Re: Batch Merge Alpha and RGB images together (same filenames - different extensions)

Posted: 2019-03-21T11:33:14-07:00
by snibgo
What version IM, on what platform? I assume IM v6 on Windows.

You want to loop through all the PNG files, or all the TIFF files, but not both. Instead of "*", I suggest "*.png".

Within the convert command, you use %g which is the drive, directory, name and extension. I suggest "%~dpng.png" and "%~dpng.tiff" etc instead.

Re: Batch Merge Alpha and RGB images together (same filenames - different extensions)

Posted: 2019-03-21T12:03:05-07:00
by Zeneric

Code: Select all

for /r %g in (*.png) do magick convert "%~dpng.png" "%~dpng.tiff" -alpha off -compose CopyOpacity -composite "%~dpng.tga"
Works.
Thank you for answering.