How can I automatically generate composite images by layering source images randomly in Windows?

Issue

Hi I’m interested to know how to do image composite of few image randomly from a set of different folder. I think this the answer by Mark Setchell in this thread answered my question but I’m on windows and I do not understand how to use this script in BAT file in Windows. I dont have clue about $ in the unix code or if i even mentioning it correctly.

Thank you in advance.

Updated:

I have finally able to make this works. Thanks also to other thread to solve my bat command script problem.

echo OFF
cls
setlocal enableDelayedExpansion

set /a folder1=1
for %%A in (./bg/*.png) do (set fol1[!folder1!]=%%~A
set /a folder1+=1 )

set /a folder2=1
for %%B in (./frame/*.png) do (set fol2[!folder2!]=%%~B
set /a folder2+=1 )

set /a folder3=1
for %%C in (./people/*.png) do (set fol3[!folder3!]=%%~C
set /a folder3+=1 )

set /a folder4=1
for %%D in (./box/*.png) do (set fol4[!folder4!]=%%~D
set /a folder4+=1 )


set totaloutput=10

for /l %%x in (1, 1, %totaloutput%) do (

    :: Assigning random number to pick photos from array
    set /a "_rand1=(!RANDOM!* (%folder1%-1) /32768)+1"
    set /a "_rand2=(!RANDOM! * (%folder2%-1) /32768)+1"
    set /a "_rand3=(!RANDOM! * (%folder3%-1) /32768)+1"
    set /a "_rand4=(!RANDOM! * (%folder4%-1) /32768)+1"
    
    :: Assigning filename with path to the picked photos
    FOR %%A IN ("!_rand1!") DO set "file1=.\bg\!fol1[%%~A]!"
    FOR %%B IN ("!_rand2!") DO set "file2=.\frame\!fol2[%%~B]!"
    FOR %%C IN ("!_rand3!") DO set "file3=.\people\!fol3[%%~C]!"
    FOR %%D IN ("!_rand4!") DO set "file4=.\box\!fol4[%%~D]!"
    
    :: Assign output file numbering based on FOR iteration number
    set "fileoutput=output-%%~x.png"
    
    :: Final Magic
    magick convert !file1! !file2! -composite !file3! -composite !file4! -composite !fileoutput!
    
)

Output Sample:

sample output of files

Solution

Repost as an answer:

echo OFF
cls
setlocal enableDelayedExpansion

set /a folder1=1
for %%A in (./bg/*.png) do (set fol1[!folder1!]=%%~A
set /a folder1+=1 )

set /a folder2=1
for %%B in (./frame/*.png) do (set fol2[!folder2!]=%%~B
set /a folder2+=1 )

set /a folder3=1
for %%C in (./people/*.png) do (set fol3[!folder3!]=%%~C
set /a folder3+=1 )

set /a folder4=1
for %%D in (./box/*.png) do (set fol4[!folder4!]=%%~D
set /a folder4+=1 )


set totaloutput=10

for /l %%x in (1, 1, %totaloutput%) do (

    :: Assigning random number to pick photos from array
    set /a "_rand1=(!RANDOM!* (%folder1%-1) /32768)+1"
    set /a "_rand2=(!RANDOM! * (%folder2%-1) /32768)+1"
    set /a "_rand3=(!RANDOM! * (%folder3%-1) /32768)+1"
    set /a "_rand4=(!RANDOM! * (%folder4%-1) /32768)+1"
    
    :: Assigning filename with path to the picked photos
    FOR %%A IN ("!_rand1!") DO set "file1=.\bg\!fol1[%%~A]!"
    FOR %%B IN ("!_rand2!") DO set "file2=.\frame\!fol2[%%~B]!"
    FOR %%C IN ("!_rand3!") DO set "file3=.\people\!fol3[%%~C]!"
    FOR %%D IN ("!_rand4!") DO set "file4=.\box\!fol4[%%~D]!"
    
    :: Assign output file numbering based on FOR iteration number
    set "fileoutput=output-%%~x.png"
    
    :: Final Magic
    magick convert !file1! !file2! -composite !file3! -composite !file4! -composite !fileoutput!
    
)

Answered By – mAzri

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published