2

我有一个 bash 脚本,它会自动为文件夹中的每个图像添加水印。

WATERMARK="$HOME/Dropbox/logo_bw.png"
if [ ! -e "watermarked_tmp" ]
then
mkdir watermarked_tmp
fi
#loop inside all the images in folder
for image in *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG
do
if [ ! -e "$image" ] # Check if file exists.
then
continue
fi
#Retrieve size of the image and divide the lenght by 2
size=`identify -format %[fx:w/4,279] $image`
#Apply the watermark and create a new image in the "watermarked" subfolder
composite  -dissolve 10% -quality 100 -gravity SouthEast -background none \( $WATERMARK -geometry ${size} \) ${image} watermarked_tmp/${image}
done

我想使用 Automator 从此代码创建一个文件夹操作。有人知道如何传递当前目录及其文件吗?我试着做,但它失败了for image in *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG

4

1 回答 1

4

将传递输入设置为参数并使用 for 循环,例如for f; do

watermark=~/a.png
d=~/watermarked_temp
mkdir -p $d
shopt -s nocasematch
for f; do
  [[ $f =~ .*\.(jpe?g|png)$ ]] || continue
  target="$d/${f##*/}"
  size=$(identify -format '%[fx:w/4,279]' "$f")
  composite -dissolve 10% -gravity SouthEast\
  \( $watermark -geometry $size \) "$f" -quality 100 "$target"
done
于 2013-07-31T21:35:22.323 回答