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

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
Zeneric
Posts: 2
Joined: 2019-03-21T10:03:10-07:00
Authentication code: 1152

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Zeneric
Posts: 2
Joined: 2019-03-21T10:03:10-07:00
Authentication code: 1152

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

Post 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.
Post Reply