Your question is unclear about:
- what your input and expected output images look like or how big they are,
- whether you actually need the intermediate images or just the montage,
- what the actual issue is with
for
loops
So here are some ideas...
Option 1
This one avoids for
loops and multiple invocations of magick
by using a single magick
and loading the side
image just once and cloning it in memory:
magick side.png \
\( +clone image_1.png +append -write out_1.png +delete \) \
\( +clone image_2.png +append -write out_2.png +delete \) \
\( +clone image_3.png +append -write out_3.png +delete \) \
\( +clone image_4.png +append -write out_4.png +delete \) \
\( +clone image_5.png +append -write out_5.png +delete \) \
image_6.png +append out_6.png
It produces 6 output files as follows:






Option 2
This one avoids for
loops by running 6 copies of magick
in parallel:
magick side.png image_1.png +append out_1.png &
magick side.png image_2.png +append out_2.png &
magick side.png image_3.png +append out_3.png &
magick side.png image_4.png +append out_4.png &
magick side.png image_5.png +append out_5.png &
magick side.png image_6.png +append out_6.png &
wait
It produces the same 6 output files as above.
Option 3
This does the same by using GNU Parallel to do it more succinctly:
parallel magick side.png image_{}.png +append out_{}.png ::: {1..6}
Option 4
If you don't need the intermediate files, and just want the montage:
parallel -k magick side.png {} +append ppm:- ::: image_*png | magick montage -tile 2x3 -geometry +5+5 ppm:- montage.png

Option 5
This is much the same, avoiding producing the intermediate output files, and also avoiding using GNU Parallel:
magick side.png \
\( +clone image_1.png +append -write ppm:- +delete \) \
\( +clone image_2.png +append -write ppm:- +delete \) \
\( +clone image_3.png +append -write ppm:- +delete \) \
\( +clone image_4.png +append -write ppm:- +delete \) \
\( +clone image_5.png +append -write ppm:- +delete \) \
image_6.png +append ppm:- | magick montage -background black -geometry +5+10 -tile 2x3 ppm:- montage.png

Option 6
This one uses no for
loops, a single process, no separate montage
command and generates no intermediate files:
magick side.png -write MPR:side +delete \
\( MPR:side image_1.png MPR:side image_2.png +append \) \
\( MPR:side image_3.png MPR:side image_4.png +append \) \
\( MPR:side image_5.png MPR:side image_6.png +append \) \
-append montage.png

Replace the +append
and -append
with -smush for more layout and inter-image spacing flexibility.
Option 7
Maybe something like this with -smush
:
magick side.png -write MPR:side +delete -background cyan \
\( MPR:side image_1.png MPR:side image_2.png +smush 10 \) \
\( MPR:side image_3.png MPR:side image_4.png +smush 10 \) \
\( MPR:side image_5.png MPR:side image_6.png +smush 10 \) \
-smush 30 montage.png

My guess is that option 6 would be the fastest on most machines in most circumstances, if it is flexible enough for you. If you need more flexibility, go with option 7 or 5.
Keywords: ImageMagick, image processing, montage, layout, parallel, smush.