O
O
oleww052018-12-28 17:54:12
bash
oleww05, 2018-12-28 17:54:12

How to stitch an image in ImageMagic?

I use a loop

#!/bin/bash
z1=({0..3}); z2=({4..7}) #...
for((i = 1; i < 3; ++i)); do
declare -n a=z$i
for n in ${a[@]}; do
echo montage -monitor /untitled/a/$i/$n.jpg -geometry +0+0 -tile 4x1 /untitled/b/$i.jpg
done
done

В результате оно просто перезаписывает изображение в 1.jpg и 2.jpg, но не склеивает в 1 файл
montage -monitor /untitled/a/1/0.jpg -geometry +0+0 -tile 4x1 /untitled/b/1.jpg
montage -monitor /untitled/a/1/1.jpg -geometry +0+0 -tile 4x1 /untitled/b/1.jpg
montage -monitor /untitled/a/1/2.jpg -geometry +0+0 -tile 4x1 /untitled/b/1.jpg
montage -monitor /untitled/a/1/3.jpg -geometry +0+0 -tile 4x1 /untitled/b/1.jpg

montage -monitor /untitled/a/2/4.jpg -geometry +0+0 -tile 4x1 /untitled/b/2.jpg
montage -monitor /untitled/a/2/5.jpg -geometry +0+0 -tile 4x1 /untitled/b/2.jpg
montage -monitor /untitled/a/2/6.jpg -geometry +0+0 -tile 4x1 /untitled/b/2.jpg
montage -monitor /untitled/a/2/7.jpg -geometry +0+0 -tile 4x1 /untitled/b/2.jpg

If you do this, it works, but manually prescribing is not suitable:
montage -monitor /untitled/a/1/{0..3}.jpg -geometry +0+0 -tile 4x1 /untitled/b/1.jpg
montage -monitor /untitled/a/2/{4..7}.jpg -geometry +0+0 -tile 4x1 /untitled/b/2.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-12-28
@oleww05

If you do this, it works, but manually prescribing is not suitable:

How about fixing the script?
#!/bin/bash
z1=({0..3}); z2=({4..7}) #...
for((i = 1; i < 3; ++i)); do
declare -n a=z$i
FILES=()
for n in ${a[@]}; do
FILES[${#FILES[@]}]="/untitled/a/$i/$n.jpg"
done
montage -monitor "${FILES[@]}" -geometry +0+0 -tile 4x1 /untitled/b/$i.jpg
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question