像这样:
#!/bin/bash
for f in *.png
do
read w h <<< $(convert "$f" -ping -format "%w %h" info: )
if [ $w -gt $h ]; then
echo "$f is $h tall and $w wide (landscape)"
convert watermark-horizonal.png "$f" "wm-$f"
else
echo "$f is $h tall and $w wide (portrait)"
convert watermark-vertical.png "$f" "wm-$f"
fi
done
如果你想递归,你可以这样做:
#!/bin/bash
find . -name "*.png" -print0 | while read -d $'\0' f
do
read w h <<< $(convert "$f" -ping -format "%w %h" info: )
if [ $w -gt $h ]; then
echo "$f is $h tall and $w wide (landscape)"
else
echo "$f is $h tall and $w wide (portrait)"
fi
done
保存在一个名为 的文件中go
,然后在终端中键入以下内容
chmod +x go # Do this just ONCE to make script executable
./go # Do this any number of times to run it
顺便说一句,我使用以下命令进行水印:
composite -dissolve 50% -resize "1x1<" -gravity center copyright.png x.png x.png