Recursive compositing

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
djac
Posts: 1
Joined: 2012-03-06T10:58:42-07:00
Authentication code: 8675308

Recursive compositing

Post by djac »

Using a glob I'm trying to repetitively composite two files, files that are named identically but reside in different folders: "Old" and "New". E.g.:

New/image1.png
Old/image1.png

Using a glob on the first input file and an explicit file name on the second this command would work fine:

convert Old/*.png -set filename:nameroot '%t' New/image1.png -composite 'OutFolder/%[filename:nameroot].gif'

I want to fill the folders with pairs of files and want a composite out of each: E.g.:

New/image1.png and Old/image1.png would composite to OutFolder/image1.gif
New/image2.png and Old/image2.png would composite to OutFolder/image2.gif
New/image3.png and...

If I could use the filename % escape in the second input filename something like this pseudo code might work:

convert Old/*.png -set filename:nameroot '%t' 'New/%[filename:nameroot].png' -composite 'OutFolder/%[filename:nameroot].gif'

This doesn't work for at least two reasons:
1. The *.png glob would capture everything into a long list of files that would be composited. We just want one file pair composited at a time.
2. A filename % escape (%[filename:nameroot]) is designed only to work on the output filename, not an input filename.

Is there any way to do this sort of recursive compositing in a single command?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Recursive compositing

Post by anthony »

Your best option is to create a script to loop over the images and work out the two filenames to merge.

IMv7 will have more possibilities, but general percent escapes will be added to reading and writing filenames. An exception may be the special %[filename:....] escape that is currently only available for write but not to read.

Note that at this time sub-string handling and string/number formating is not provided by percent escapes. Ideas are however 'floating around'...
http://www.imagemagick.org/Usage/IMv7_F ... rcent.html

I have also have had a request for option to provide 'literal' filename handling. That is no coder, %d, or [...] syntax handling of the given string. That however is very low priority.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply