mono/packages/media/tests/watermark-test.sh
2025-08-11 12:25:45 +02:00

213 lines
6.3 KiB
Bash

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Create test output directory
mkdir -p tests/watermark-test-output
echo -e "${BLUE}Building project...${NC}"
npm run build
echo
echo -e "${BLUE}Test 1: Text watermark on single image${NC}"
pm-media watermark \
--src "tests/images/in/DSC01177.JPG" \
--dst "tests/watermark-test-output/text-watermark-single.jpg" \
--watermark "© 2024 Polymech" \
--position "bottom-right" \
--fontSize 32 \
--color "#ffffff" \
--strokeColor "#000000" \
--opacity 0.8
echo -e "${GREEN}✓ Text watermark test completed${NC}"
echo
echo -e "${BLUE}Test 2: Image watermark on single image${NC}"
pm-media watermark \
--src "tests/images/in/DSC01301.JPG" \
--dst "tests/watermark-test-output/image-watermark-single.jpg" \
--watermark "tests/images/watermark-add/polymech-saw.svg" \
--position "bottom-right" \
--sizePct 0.15 \
--opacity 0.85
echo -e "${GREEN}✓ Image watermark test completed${NC}"
echo
echo -e "${BLUE}Test 3: Text watermark with different positions${NC}"
positions=("top-left" "top-right" "bottom-left" "bottom-right" "center")
for pos in "${positions[@]}"; do
echo " Testing position: $pos"
pm-media watermark \
--src "tests/images/in/DSC01325.JPG" \
--dst "tests/watermark-test-output/text-$pos.jpg" \
--watermark "Polymech $pos" \
--position "$pos" \
--fontSize 24 \
--color "#ff0000"
done
echo -e "${GREEN}✓ Position tests completed${NC}"
echo
echo -e "${BLUE}Test 4: Image watermark with different sizes${NC}"
sizes=(0.1 0.2 0.3)
for size in "${sizes[@]}"; do
echo " Testing size: ${size}0% of image width"
pm-media watermark \
--src "tests/images/in/DSC01354.JPG" \
--dst "tests/watermark-test-output/image-size-$size.jpg" \
--watermark "tests/images/watermark-add/polymech-saw.svg" \
--sizePct "$size" \
--position "top-left"
done
echo -e "${GREEN}✓ Size tests completed${NC}"
echo
echo -e "${BLUE}Test 5: Batch watermarking multiple images${NC}"
pm-media watermark \
--src "tests/images/in/sub/*.JPG" \
--dst "tests/watermark-test-output/batch-&{SRC_NAME}_watermarked.&{SRC_EXT}" \
--watermark "Batch Test" \
--fontSize 20 \
--position "center" \
--alt
echo -e "${GREEN}✓ Batch watermark test completed${NC}"
echo
echo -e "${BLUE}Test 6: Dry run test${NC}"
pm-media watermark \
--src "tests/images/in/perspective_naked.jpg" \
--dst "tests/watermark-test-output/dry-run-test.jpg" \
--watermark "Should not create file" \
--dry
echo -e "${GREEN}✓ Dry run test completed${NC}"
echo
echo -e "${BLUE}Test 7: High-resolution SVG watermark${NC}"
pm-media watermark \
--src "tests/images/in/DSC01577.JPG" \
--dst "tests/watermark-test-output/svg-high-res.jpg" \
--watermark "tests/assets/test-logo.svg" \
--sizePct 0.25 \
--opacity 0.7 \
--position "center"
echo -e "${GREEN}✓ High-resolution SVG test completed${NC}"
echo
echo -e "${BLUE}Test 8: Different image formats${NC}"
formats=("jpg" "png" "webp")
for format in "${formats[@]}"; do
if ls tests/images/in/*.$format 1> /dev/null 2>&1; then
echo " Testing $format format"
pm-media watermark \
--src "tests/images/in/*.$format" \
--dst "tests/watermark-test-output/format-test-&{SRC_NAME}.&{SRC_EXT}" \
--watermark "Format: $format" \
--fontSize 16 \
--alt
fi
done
echo -e "${GREEN}✓ Format tests completed${NC}"
echo
echo -e "${BLUE}Test 9: Default tokenizer syntax (without --alt)${NC}"
pm-media watermark \
--src "tests/images/in/parts.png" \
--dst "tests/watermark-test-output/default-\${SRC_NAME}_processed.\${SRC_EXT}" \
--watermark "Default Syntax" \
--fontSize 18 \
--position "top-right"
echo -e "${GREEN}✓ Default tokenizer test completed${NC}"
echo
echo -e "${BLUE}Test 11: Error handling - Invalid watermark file${NC}"
set +e # Allow errors for this test
pm-media watermark \
--src "tests/images/in/DSC01177.JPG" \
--dst "tests/watermark-test-output/error-test.jpg" \
--watermark "non-existent-file.png" 2>&1 | grep -q "not found"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Error handling test passed${NC}"
else
echo -e "${RED}✗ Error handling test failed${NC}"
fi
set -e
echo
echo -e "${BLUE}Test 12: Registry-style command (using alt tokenizer)${NC}"
pm-media watermark \
--src "tests/images/in/barrel.png" \
--dst "tests/watermark-test-output/&{SRC_NAME}_watermarked.&{SRC_EXT}" \
--watermark "tests/images/watermark-add/polymech-saw.svg" \
--alt \
--position "bottom-right" \
--opacity 0.85
echo -e "${GREEN}✓ Registry-style test completed${NC}"
echo
echo -e "${BLUE}Test 13: Default tokenizer with POLYMECH-ROOT path${NC}"
pm-media watermark \
--src "tests/images/in/perspective_naked.jpg" \
--dst "tests/watermark-test-output/polymech-default-\${SRC_NAME}.\${SRC_EXT}" \
--watermark "\${POLYMECH-ROOT}/nordin-ex/branding/logos/polymech-saw-ex.svg" \
--sizePct 0.18 \
--position "bottom-left" \
--opacity 0.9
echo -e "${GREEN}✓ POLYMECH-ROOT default tokenizer test completed${NC}"
echo
echo -e "${BLUE}Test 14: Alt tokenizer with POLYMECH-ROOT path${NC}"
pm-media watermark \
--src "tests/images/in/DSC01301.JPG" \
--dst "tests/watermark-test-output/polymech-alt-&{SRC_NAME}_branded.&{SRC_EXT}" \
--watermark "&{POLYMECH-ROOT}/nordin-ex/branding/logos/polymech-saw-ex.svg" \
--sizePct 0.22 \
--position "top-left" \
--opacity 0.75 \
--alt
echo -e "${GREEN}✓ POLYMECH-ROOT alt tokenizer test completed${NC}"
echo
echo -e "${BLUE}Test 15: Cache functionality test${NC}"
# First, create a watermarked file
pm-media watermark \
--src "tests/images/in/v1.0.1.JPG" \
--dst "tests/watermark-test-output/cache-test.jpg" \
--watermark "Original Watermark" \
--fontSize 24
# Then try to overwrite it with cache enabled (should skip)
pm-media watermark \
--src "tests/images/in/v1.0.1.JPG" \
--dst "tests/watermark-test-output/cache-test.jpg" \
--watermark "This should be skipped" \
--fontSize 24 \
--cache
echo -e "${GREEN}✓ Cache functionality test completed${NC}"
echo
echo -e "${YELLOW}=== Test Summary ===${NC}"
echo "All tests completed! Check output files in: tests/watermark-test-output/"
echo
echo "Generated files:"
ls -la tests/watermark-test-output/ | grep -E '\.(jpg|png|webp)$' | wc -l | xargs echo " Total images created:"
echo
echo -e "${GREEN}✓ All watermark tests passed successfully!${NC}"