Created
January 22, 2023 16:22
-
-
Save rbrady/d4c1a9667586ee2b7284c4374bc19e2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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