我有一大堆 jpeg。我想编写一个 shell 脚本,随机选择 5 个图像,然后使用 imageMagick 将它们放入蒙太奇中,然后打开这个蒙太奇文件。我希望这个过程每 10 秒发生一次。
我试过这个脚本
for f in *.jpg
do
shuf -ezn 5 * | xards -0 -n1 | montage *.jpg | display montage.jpg
done
但它不起作用
它打开所有图像并给出以下错误消息
image.sh 7: image.sh: Xards: not found
go.sh 脚本与图像保存在同一文件夹/目录中,现在如下所示:
#!/bin/bash
# Get list of files into array - just once at start
files=(*.jpg)
# Do forever
first=0
while :; do
# Shuffle array
files=( $(shuf -e "${files[@]}") )
# Make montage of first 5 images in shuffled array
magick montage ${files[0]} ${files[1]} ${files[2]} ${files[3]} ${files[4]} montage.jpg
# Start displaying if first pass - leaving "display" running in background updating itself every second
if [ $first -eq 0 ] ; then
display -update 1 montage.jpg &
first=1
fi
# Snooze 10 and repeat
sleep 10
done
然而这正在回归
go.sh: 4: go.sh: Syntax error: "(" unexpected
然而,当我跑步时
bash go.sh
ImageMagick 在一个蒙太奇中打开文件夹中的所有图像,我收到以下错误
go.sh: line 12: magick: command not found
像这样的事情:
#!/bin/bash
# Get list of files into array - just once at start
files=(*.jpg)
# Do forever
first=0
while :; do
# Shuffle array
files=( $(shuf -e "${files[@]}") )
# Make montage of first 5 images in shuffled array
magick montage ${files[0]} ${files[1]} ${files[2]} ${files[3]} ${files[4]} montage.jpg
# Start displaying if first pass - leaving "display" running in background updating itself every second
if [ $first -eq 0 ] ; then
display -update 1 montage.jpg &
first=1
fi
# Snooze 10 and repeat
sleep 10
done
或者这样可能更容易理解:
#!/bin/bash
# Get list of files into array
files=(*.jpg)
montage=/tmp/montage.jpg
# Create initial "Loading sign"
convert -background black -fill white -pointsize 64 label:"Loading" $montage
display -update 1 $montage &
# Do forever
while :; do
# Shuffle array
files=( $(shuf -e "${files[@]}") )
# Make montage
magick montage ${files[0]} ${files[1]} ${files[2]} ${files[3]} ${files[4]} $montage
# Snooze 10 and repeat
sleep 10
done
macOS 用户可能没有 ImageMagick 内置的 X11 支持,他们可以安装feh
using homebrew像这样还有shuf
(实际命令是gshuf
)来自 GNU coreutils:
brew install feh
brew install coreutils
并尝试以下版本:
#!/bin/bash
# Get list of files into array
files=(*.jpg)
montage=/tmp/montage.jpg
# Create initial "Loading sign"
convert -background black -fill white -pointsize 64 label:"Loading" $montage
# Display "feh" running continuously in background passing the same image twice so we can cycle through the list!
feh --title "My Funky Montage" $montage $montage &
fehpid=$!
# Do forever
while :; do
# Shuffle array
files=( $(gshuf -e "${files[@]}") )
# Make montage
magick montage ${files[0]} ${files[1]} ${files[2]} ${files[3]} ${files[4]} $montage
# Cycle feh to next image
kill -s USR1 $fehpid
# Snooze 10 and repeat
sleep 10
done
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)