Page 1 of 1

Generate all possible heirarchical layer composites

Posted: 2017-02-28T11:49:36-07:00
by MajinCry
Yeah, just found out that the word hierarchical exists. Bloody ugly word I tell ya.

Anywho, I've got a bunch of images I need to separate into pieces, and then assemble each possible combination of pieces into layers. I've done this a few times by hand in Photoshop, and boy am I tired of it. Just having 5 separate images to combine means I've to save easily over a hundred images. I've made a quick wee archive with solid colour images (psd with layers, source images, and a few example results) to give an idea of what I'm trying to achieve.

Kinda messed up a bit, as I should have shifted the "ABackground" and "BForeground" layers around (i.e, more saved combinations), but the burnout is rather real. Can't seem to make any attachments, so I uploaded it to Mega: https://mega.nz/#!vxVyFZZZ!NTCIOmcZxdvl ... _eHaM37XH0


To elaborate on what I'm trying to achieve:

The folders are named in a hierarchy. The prefix A denotes the background image, the prefix B denotes the image to lay over the background, the prefix C denotes what gets laid over C, etc. Not all "pieces" will overlap, which is expected behaviour.

However, the images in folder A should never be laid on top of the images in folder B. The images in folder B should never be laid on top of the images in folder C. Etc.

The image pieces will be in .png format, and there is no need to re-position them as all the images will have the same width and height.


So aye, is there any good way to do this with ImageMagick? I can do a bit of Pascal through the Lazarus IDE, if that makes things easier.

Re: Generate all possible heirarchical layer composites

Posted: 2017-02-28T12:00:51-07:00
by snibgo
It sounds as if you want to loop through all the images in A. For each one, loop through all images in B, and for each of those loop through all images in C. Within these nested loops, "-layers merge" the three images.

Is that right?

Then it is a simple task in a shell script.

Re: Generate all possible heirarchical layer composites

Posted: 2017-02-28T12:02:10-07:00
by MajinCry
snibgo wrote: 2017-02-28T12:00:51-07:00 It sounds as if you want to loop through all the images in A. For each one, loop through all images in B, and for each of those loop through all images in C. Within these nested loops, "-layers merge" the three images.

Is that right?

Then it is a simple task in a shell script.
Yup, that's what I'm looking for. There could be more/fewer folders, with more/fewer images in each of them, mind. If this can be done with just a bat file...Oooh boy!

Edit: Tried googling terms like "bat nested folders loop", but I couldn't find anything particularly relevant. Mind helping me along a tad?

Re: Generate all possible heirarchical layer composites

Posted: 2017-02-28T12:32:23-07:00
by snibgo
Sure it can be done, very easily. In a BAT file, use a "for" loop. I suggest you type "for /?" at the command line to find the syntax. Then experiment.

Re: Generate all possible heirarchical layer composites

Posted: 2017-02-28T12:54:55-07:00
by MajinCry
snibgo wrote: 2017-02-28T12:32:23-07:00 Sure it can be done, very easily. In a BAT file, use a "for" loop. I suggest you type "for /?" at the command line to find the syntax. Then experiment.
Geh, bat is a bit beyond me. Got this far (formatted for ease of reading):

Code: Select all

For /D %%S in (*.*) do
  (  For /r [%%dpn~S] %%F in (*.png) do
    (
    )
  )
So what the above should do:

In each folder
For each .png file


But that doesn't take into account the hierarchy (i.e, loop the folders alphabetically). And I have to somehow get all the names of the files in each subfolder, rather than just the first file the bat file comes across.

Re: Generate all possible heirarchical layer composites

Posted: 2017-02-28T22:41:07-07:00
by snibgo
Your code searches for all the directories within a given directory. So you might have any number?

Are your directories in a hierarchy? How many directories within each directory, roughly? How many levels of directory? Exactly three, or could be any number? If so then again, how many, roughly?