Reputation: 23
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:
Upvotes: 1
Views: 261
Reputation: 23
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!
)
Upvotes: 1
Reputation: 207445
I don't speak "Windows", but can give you half an answer, which you or somebody else can hopefully expand out into something that works.
The basic ImageMagick command you will need to run is:
magick BACKGROUND.PNG OVERLAY1.PNG OVERLAY2.PNG -compose over -composite RESULT.PNG
If you want to resize them all to the same size before overlaying, use:
magick BACKGROUND.PNG OVERLAY1.PNG OVERLAY2.PNG -resize 800x600! -compose over -composite RESULT.PNG
If you want to resize them individually before overlaying, use:
magick BACKGROUND.PNG ( OVERLAY1.PNG -resize 400x300 ) ( OVERLAY2.PNG -resize 100x100 ) -compose over -composite RESULT.PNG
So try that with some of your images and see what you get. Update your question with your code and representative sample images.
Upvotes: 0