首页 > 解决方案 > In Terminal - For-loop 将每张连续的 18 张图片拼接成一张图片

问题描述

我有一个小脚本,可以下载大图片的一部分,然后尝试将它们拼接在一起。

例如,我有 234 张小图片,它们合起来就构成了一张大全景图。如何编写我的脚本(在 macOS 上的 zsh 中),以便它垂直附加一组连续的 18 张图片(即图片 1..18,然后是 19..36 等),然后缝合所有生成的 12 个垂直条图片一起到最终输出?

这将是我脚本的相关部分。此时变量y将包含数字 234,即下载的图片总量。

#!/bin/bash
((y = 234))
((h = 1)) # set up the counter

for (( z = 1; z <= $y; z+=1 )); do # the for-loop should start with the first picture, going until the maximum amount (here 234) and iterate by one
  convert -append $(ls $z.jpg | sort -V) $h-x.jpg # here the script shall combine vertically 18 pictures to one picture set called 1-x.jpg, subsequently 2-x.jpg, 3-x.jpg etc.
  ((z % 18 != 0)) # after every 18th picture it shall increment the counter
  ((h = h + 1))
done

convert +append $(ls $h-* | sort -V) final.jpg # finally the script shall take all 12 pictures vertically congregated to one final picture by appending them horizontally together

目前的脚本什么都不做,没有拼接,也没有给我任何错误信息。

我的代码有什么问题?

标签: bashloopsterminalzsh

解决方案


推荐阅读