Skip to content

zafrkaya/woo-commerce-image-watermark

Repository files navigation

WooCommerce Image Watermark & Protector

A powerful WordPress plugin that protects your WooCommerce product images with dynamic watermarks and right-click protection.

Features

Dynamic Watermarking

  • Apply watermarks on-the-fly without modifying original images
  • Original files remain completely untouched in your media library
  • Smart caching system for optimal performance

Live Preview

  • Real-time preview of watermark placement
  • See exactly how your watermark will look before saving
  • Instant updates as you adjust settings

Flexible Configuration

  • 4 Position Options: Top-left, top-right, bottom-left, bottom-right
  • Adjustable Opacity: Control transparency from 0-100%
  • Scalable Size: Resize watermark from 10% to 200% of original
  • PNG Support: Use transparent PNG images for professional watermarks

Image Protection

  • Disable right-click context menu on product images
  • Prevent drag-and-drop image saving
  • Disable text selection on images
  • Protection for WooCommerce zoom and lightbox

Smart Caching

  • Automatically cache watermarked images
  • One-click cache clearing from admin panel
  • Automatic cleanup of old cache files (30+ days)
  • Cache invalidation when settings change

Technical Specifications

Requirements

  • WordPress: 5.8 or higher
  • WooCommerce: 5.0 or higher
  • PHP: 7.4 or higher
  • PHP Extensions: GD Library

How It Works

WooCommerce Image Detection

The plugin uses multiple strategies to detect WooCommerce product images:

  1. Post Parent Check: Verifies if attachment's parent is a product post type
  2. Gallery Meta Check: Searches product gallery metadata
  3. Context Check: Detects if request is from a product page

Dynamic Watermark Application

Image Request → Detection → Settings Check → Cache Check
                                  ↓
                          Apply Watermark (GD Library)
                                  ↓
                          Save to Cache → Display

Caching System

  • Cache filename: {attachment_id}_{settings_hash}.jpg
  • Cache location: wp-content/uploads/watermarked-cache/
  • Cache key includes: position, opacity, scale, watermark ID

Installation

Quick Install

  1. Upload plugin to /wp-content/plugins/woocommerce-image-protector/
  2. Activate via WordPress admin panel
  3. Navigate to WooCommerce > Image Protection
  4. Configure settings and save

See INSTALLATION.md for detailed installation instructions.

Configuration

Basic Setup

  1. Upload Watermark: Click "Select Watermark Image" and choose a PNG file
  2. Select Position: Choose from 4 corner positions
  3. Adjust Opacity: Use slider to set transparency (70% recommended)
  4. Set Scale: Resize watermark to fit your needs (100% default)
  5. Enable Features: Toggle watermark and right-click protection
  6. Save Settings: Click "Save Settings" button

Advanced Options

  • Clear Cache: Remove all cached watermarked images
  • Preview: Use live preview to test different settings

File Structure

woocommerce-image-protector/
├── woocommerce-image-protector.php    # Main plugin file
├── admin/                              # Admin panel components
│   ├── admin-settings.php             # Settings page UI
│   ├── settings-handler.php           # Settings validation & save
│   └── preview-generator.php          # Live preview generator
├── includes/                           # Core functionality
│   ├── image-detector.php             # WooCommerce image detection
│   ├── watermark-handler.php          # Watermark application (GD Library)
│   ├── cache-manager.php              # Cache management system
│   └── image-filter.php               # WordPress/WooCommerce hooks
├── assets/                             # Frontend & admin assets
│   ├── js/
│   │   ├── image-protection.js        # Right-click protection
│   │   └── admin-preview.js           # Admin live preview
│   ├── css/
│   │   ├── protection.css             # Frontend protection styles
│   │   └── admin-style.css            # Admin panel styles
│   └── img/
│       └── preview-placeholder.jpg    # Admin preview placeholder
├── readme.txt                          # WordPress.org readme
├── INSTALLATION.md                     # Installation guide
└── create-placeholder.php              # Placeholder image generator

Usage

For Site Administrators

After configuration, watermarks are automatically applied to all WooCommerce product images. No additional action needed.

For Developers

The plugin provides several hooks for customization:

// Modify watermark settings before application
add_filter('wip_watermark_settings', function($settings) {
    $settings['opacity'] = 80;
    return $settings;
});

// Add custom image detection logic
add_filter('wip_is_product_image', function($is_product, $attachment_id) {
    // Your custom logic
    return $is_product;
}, 10, 2);

Security

  • Nonce verification on all AJAX requests
  • Capability checks (manage_woocommerce)
  • Input sanitization and validation
  • Path traversal protection
  • MIME type validation for watermark uploads

Performance

  • Smart caching system minimizes server load
  • Watermarks generated once and cached
  • Automatic cleanup of old cache files
  • Conditional asset loading (only on product pages)

Limitations

  • Right-click protection is not foolproof (screenshots, developer tools still work)
  • Requires PHP GD Library extension
  • PNG format recommended for watermarks
  • Cache directory must be writable

Troubleshooting

Watermark Not Showing

  • Verify PHP GD Library is installed
  • Check if watermark image is uploaded
  • Ensure "Enable Watermark" is checked
  • Clear watermark cache

Permission Errors

chmod 755 wp-content/uploads/watermarked-cache/

Cache Issues

  • Clear browser cache
  • Use "Clear Watermark Cache" button in admin
  • Check directory permissions

FAQ

Q: Does this modify my original images?
A: No! Watermarks are applied dynamically. Original files are never modified.

Q: Will this slow down my site?
A: No. The caching system ensures watermarks are only generated once per image/settings combination.

Q: Can users still save my images?
A: Right-click protection makes it harder, but determined users can still use screenshots or developer tools. No protection is 100% foolproof.

Q: What format should I use for watermarks?
A: PNG with transparency is highly recommended for best results.

Support

For issues, questions, or feature requests:

  • Check the troubleshooting section above
  • Review the installation guide
  • Visit the plugin support forum

License

GPL v2 or later

Credits

  • Uses PHP GD Library for image manipulation
  • Compatible with WooCommerce gallery features
  • Works with PhotoSwipe lightbox

Changelog

Version 1.0.0

  • Initial release
  • Dynamic watermark application
  • Live preview functionality
  • 4 corner position options
  • Adjustable opacity and scale
  • Right-click and drag protection
  • Smart caching system
  • WooCommerce integration

Made with care for WooCommerce store owners who want to protect their product images.

About

WooCommerce Image Watermark & Protector

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors