【发布时间】:2021-12-22 01:44:26
【问题描述】:
这是this question 的后续,ign 提出问题,Marc Setchell 专业回答
虽然我希望找到一种方法来避免在随机化过程中形成重复,但它工作得很好。我将对一堆图层进行数百种变体,但存在细微的差异,因此我无法真正进入并以故障安全的方式发现重复项。
这是我正在使用的代码,如上所述 - 归功于 Marc Setchell!
#!/bin/bash
# Number of output files - edit freely :-)
NFILES=10
# Build arrays of filenames in each layer, assume directories are "Layer0", "Layer1" etc
IFS=$'\n' L0files=($(find "Layer 0" -name "*.png"))
IFS=$'\n' L1files=($(find "Layer 1" -name "*.png"))
IFS=$'\n' L2files=($(find "Layer 2" -name "*.png"))
IFS=$'\n' L3files=($(find "Layer 3" -name "*.png"))
# Produce NFILES output files
for i in `seq 1 $NFILES`; do
# Choose random index into each array of filenames
index0=$( jot -r 1 0 $((${#L0files[@]} - 1)) )
index1=$( jot -r 1 0 $((${#L1files[@]} - 1)) )
index2=$( jot -r 1 0 $((${#L2files[@]} - 1)) )
index3=$( jot -r 1 0 $((${#L3files[@]} - 1)) )
# Pick up files as specified by the random index
f0=${L0files[index0]}
f1=${L1files[index1]}
f2=${L2files[index2]}
f3=${L3files[index3]}
# Generate output filename, "output-nnn.png"
# ... where nnn starts at 0 and goes up till no clash
i=0
while :; do
out="output-$i.png"
[ ! -f "$out" ] && break
((i++))
done
echo $f0, $f1, $f2, $f3 "=> $out"
convert "$f0" "$f1" -composite "$f2" -composite "$f3" -composite "$out"
done
【问题讨论】:
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
-
我正在寻找上面的代码 - 为了创建随机图像组合而对多个 png 进行分层 - 进行了编辑,以避免在随机化过程中产生重复。 @xenoid 在如何更改输出文件名方面非常有帮助,这太棒了,但如果它试图创建重复的图像,它现在会暂停 - 并且只有在移动原始文件后才会继续。所以我现在只需要知道如何让它在输出文件名的末尾添加一个数字,以便它不会在重复时暂停。然后我可以按名称搜索并查看重复项的位置,然后将其删除。
标签: image-processing scripting duplicates imagemagick photoshop