I use the following code to draw an overlay box over another image
convert \
-background '#0002' \
-gravity Center \
-fill white \
-size ${page_width}x30 \
caption:"" \
"${img}" \
+swap \
-geometry +0+100 \
-composite \
"${img}"
however, I want to draw it on multiple positions, for example every other 100 pixels from top to the bottom of the image. I can use a loop for this purpose, but I would like to know if there is a better command or solution for this problem?
You can do that by tiling your pattern over the image using Imagemagick.
Input:
# Line 1: read the input
# Line 2: create the tile (spacing set to 50 in transparent section)
# Line 3: tile it out over the size of the input by replacing it on the input
# Line 4: do the composite
# Line 5: save the output
convert lena.png \
\( -size 256x30 xc:"#0002" -size 256x50 xc:none -append -write mpr:tile +delete \) \
\( -clone 0 -tile mpr:tile -draw "color 0,0 reset" \) \
-compose over -composite \
result.png
Result: