1

如何在不同的图像(水平和垂直)上批量应用不同的水印(水平和垂直)?

我有数百个像这样的PNG文件的文件夹树(例如):

modern
classic
balance

我有两个水印:

watermark-horizontal.png
watermark-vertical.png

如何在水平照片上应用水平水印,在垂直照片上应用垂直水印?

我可以为这样的单张照片做到这一点:

convert watermark-horizonal.png some-horizontal.png result.png

我怎样才能为许多人做同样的事情?

4

1 回答 1

2

像这样:

#!/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
于 2014-07-10T11:10:18.653 回答