Skip to content

Instantly share code, notes, and snippets.

@rbrady
Created January 22, 2023 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbrady/d4c1a9667586ee2b7284c4374bc19e2e to your computer and use it in GitHub Desktop.
Save rbrady/d4c1a9667586ee2b7284c4374bc19e2e to your computer and use it in GitHub Desktop.
#!/bin/bash
directory=${1:-""}
percentage=${2:-"25"}
watermark_image=${3:-"watermark.png"}
location="southwest"
if [ -z "$directory" ]; then
echo "Error: directory argument is required"
exit 1
fi
if [ -z "$percentage" ]; then
echo "Error: percentage argument is required"
exit 1
fi
if [ -z "$watermark_image" ]; then
echo "Error: watermark_image argument is required"
exit 1
fi
for file in "$directory"/*
do
if [[ $file == *.jpg || $file == *.JPG || $file == *.jpeg || $file == *.JPEG || $file == *.png || $file == *.PNG ]]; then
# Resize image
convert "$file" -resize "${percentage}%" "$file"
# Add watermark
convert "$file" "$watermark_image" -gravity "$location" -composite "$file"
fi
done
echo "Watermark added successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment