1. Go to this page and download the library: Download tourze/blind-watermark library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tourze / blind-watermark example snippets
use Tourze\BlindWatermark\BlindWatermark;
$watermark = new BlindWatermark();
$watermark->embedTextToImage(
'input.jpg', // Source image path
'Copyright 2024', // Text to embed
'watermarked.jpg' // Output image path
);
use Tourze\BlindWatermark\BlindWatermark;
$watermark = new BlindWatermark();
$text = $watermark->extractTextFromImage('watermarked.jpg');
echo "Extracted text: " . $text;
use Tourze\BlindWatermark\BlindWatermark;
$watermark = new BlindWatermark();
// Configure watermark parameters
$watermark->setAlpha(90.0) // Set watermark strength (default: 36.0)
->setBlockSize(8) // Set DCT block size (default: 8)
->setPosition([3, 4]) // Set embedding position in DCT coefficients
->enableSymmetricEmbedding() // Enable flip resistance
->enableMultiPointEmbedding() // Enable enhanced robustness
->enableGeometricCorrection(); // Enable geometric transformation correction
// Embed watermark
$watermark->embedTextToImage(
'source.jpg',
'Secret Message',
'output.jpg',
'jpeg', // Output format (optional, default: jpeg)
90 // Output quality (optional, default: 90)
);
use Tourze\BlindWatermark\BlindWatermark;
$watermark = new BlindWatermark();
// Load image
$watermark->loadImage('source.jpg');
// Configure and embed
$watermark->setAlpha(50.0)
->embedText('My Watermark');
// Save result
$watermark->saveImage('output.jpg', 'jpeg', 95);
// Extract from saved image
$watermark->loadImage('output.jpg');
$extractedText = $watermark->extractText();
$watermark->enableSymmetricEmbedding();
$watermark->enableMultiPointEmbedding();
$watermark->enableGeometricCorrection();
use Tourze\BlindWatermark\BlindWatermark;
use Tourze\BlindWatermark\Exception\BlindWatermarkException;
try {
$watermark = new BlindWatermark();
$watermark->embedTextToImage('input.jpg', 'watermark', 'output.jpg');
} catch (BlindWatermarkException $e) {
echo "Error: " . $e->getMessage();
}