macos - 自动水印 - 文件夹操作

标签 macos bash imagemagick applescript

我有一个 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 行失败

最佳答案

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

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

关于macos - 自动水印 - 文件夹操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17980047/

相关文章:

image-processing - Imagemagick 'convert' : how to simply create thumbnails for a folder of images and retain their filename?

macos - 装有Docker Toolbox的Mac OSX上的Docker中的端口映射

linux - Linux bash 递归函数的返回值

php - 在服务器上将文本转换为路径(svg)?

Firebase 云函数错误生成缩略图 : spawn convert ENOENT

linux - 从变量运行 rsync 命令——不接受引用

python-3.x - 为什么在 MacOS 和 Ubuntu 上运行程序时感知时区的日期时间不同?

macos - 在 macOS Cocoa 应用程序中,如何仅显示与 NSTreeController 填充的 NSOutlineView 中的 NSPredicate 匹配的前 'x' 元素?

java - 请推荐一个将 C# 应用程序移植到 Mac 的平台?

bash - 评论中的变量扩展