Watermark Script > magick iTerminal (Macbook Pro)
brew install imagemagick
nano watermark.sh
#!/bin/bash
BASE_DIR="/Users/muhdsyafiq/Pictures/GMART AUTOCITY/CARS"
WATERMARK="/Users/muhdsyafiq/Pictures/GMART AUTOCITY/@syafiqjual transparent.png"
echo "======================================"
echo "🚗 GMART AUTOCITY WATERMARK TOOL"
echo "======================================"
# Verify watermark file exists
if [ ! -f "$WATERMARK" ]; then
echo "❌ Watermark file not found:"
echo "$WATERMARK"
exit 1
fi
########################################
# STEP 1 - REMOVE EXACT DUPLICATES
########################################
echo ""
echo "🔍 Step 1: Detecting duplicate images..."
declare -A seen_hashes
duplicates_removed=0
while IFS= read -r file
do
hash=$(md5 -q "$file")
if [[ -n "${seen_hashes[$hash]}" ]]; then
echo "🗑️ Removing duplicate:"
echo " $file"
rm -f "$file"
((duplicates_removed++))
else
seen_hashes[$hash]="$file"
fi
done < <(
find "$BASE_DIR" \
-type d -name "*_WM" -prune -o \
-type f \( \
-iname "*.jpg" -o \
-iname "*.jpeg" -o \
-iname "*.png" -o \
-iname "*.heic" -o \
-iname "*.webp" \
)
echo "🧼 Duplicate cleanup done."
echo "📊 Duplicates removed: $duplicates_removed"
########################################
# STEP 2 - WATERMARK IMAGES
########################################
echo ""
echo "🖼️ Step 2: Watermarking images..."
watermarked=0
skipped=0
while IFS= read -r file
do
dir=$(dirname "$file")
name=$(basename "$file")
folder_name=$(basename "$dir")
output_dir="$dir/${folder_name}_WM"
output_file="$output_dir/$name"
mkdir -p "$output_dir"
# Skip if already processed
if [ -f "$output_file" ]; then
echo "⏭️ Already exists:"
echo " $output_file"
((skipped++))
continue
fi
magick "$file" \
\( "$WATERMARK" \
-resize 300x300 \
-alpha set \
-channel A \
-evaluate multiply 0.25 \
+channel \) \
-gravity southeast \
-geometry +30+30 \
-composite \
"$output_file"
if [ $? -eq 0 ]; then
echo "✅ Watermarked:"
echo " $name"
((watermarked++))
else
echo "❌ Failed:"
echo " $file"
fi
done < <(
find "$BASE_DIR" \
-type d -name "*_WM" -prune -o \
-type f \( \
-iname "*.jpg" -o \
-iname "*.jpeg" -o \
-iname "*.png" -o \
-iname "*.heic" -o \
-iname "*.webp" \
)
echo ""
echo "======================================"
echo "🎉 DONE!! TOTAL SUMMARY:"
echo "======================================"
echo "✅ Watermarked : $watermarked"
echo "⏭ ️ Skipped : $skipped"
echo "🗑 ️ Duplicates : $duplicates_removed"
echo "======================================"
echo "######################################"
echo "Script written by SAsyafiq @syafiqjual"
echo "######################################"
chmod +x watermark.sh
./watermark.sh
















