Reputation: 2656
I have this working Automator/bash script, which watermarks all files which I select:
watermark=~/Dropbox/watermark.png
shopt -s nocasematch
for f; do
[[ $f =~ .*\.(jpe?g|png)$ ]] || continue
d="${f%/*}/wm_$(date +%Y_%m_%d)"
mkdir -p "$d"
target="$d/${f##*/}"
size=$(/usr/local/bin/identify -format '%[fx:w/4,279]' "$f")
/usr/local/bin/composite -dissolve 10% -gravity SouthEast\
\( $watermark -geometry $size \) "$f" -quality 100 "$target"
done
The problem with this setup, that does not work If I select folder (of course in this case I set type to Files and folders in Automator) with images inside (works only if I select images).
My second question is, how to modify this code to make selectedfolder_watermarked folders?
Upvotes: 0
Views: 616
Reputation: 27613
This script only works with folders and it saves for example ~/Desktop/dir1/file1.png
to ~/Desktop/dir1_watermarked/file1.png
:
watermark=~/Dropbox/watermark.png
shopt -s nocasematch extglob
for dir; do
mkdir "$dir"_watermarked
for f in "$dir"/*.@(png|jpg|jpeg); do
size=$(/usr/local/bin/identify -format '%[fx:w/4,279]' "$f")
/usr/local/bin/composite -dissolve 10% -gravity SouthEast \
\( $watermark -geometry $size \) "$f" -quality 100 "$dir"_watermarked/"${f##*/}"
done
done
Upvotes: 1