PHP code example of kid1296 / blind-watermark

1. Go to this page and download the library: Download kid1296/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/ */

    

kid1296 / blind-watermark example snippets



id1296\BlindWatermark\WaterMark;

// ========== embed ==========
$bwm1 = new WaterMark(passwordWm: 1, passwordImg: 1);
$bwm1->read_img('examples/pics/origin.jpg');
$wm = 'This is a test sentence.';
$bwm1->read_wm($wm, 'str');
$bwm1->embed('examples/output/embedded_str.png');
$lenWm = $bwm1->wmSize;                    // remember this length

// ========== extract ==========
$bwm2 = new WaterMark(passwordWm: 1, passwordImg: 1);
$extracted = $bwm2->extract(
    filename: 'examples/output/embedded_str.png',
    wmShape:  $lenWm,
    mode:     'str'
);
// $extracted === 'This is a test sentence.'


id1296\BlindWatermark\WaterMark;

$bits = [1,0,1,1,0,1,0,0,1,1,0,1,0,1,1,0];

// embed
$bwm1 = new WaterMark(1, 1);
$bwm1->read_img('examples/pics/origin.jpg');
$bwm1->read_wm($bits, 'bit');
$bwm1->embed('examples/output/embedded_bit.png');
$lenWm = $bwm1->wmSize;

// extract
$bwm2 = new WaterMark(1, 1);
$extracted = $bwm2->extract(
    filename: 'examples/output/embedded_bit.png',
    wmShape:  $lenWm,
    mode:     'bit'                   // returns int[] of 0/1
);
// $extracted === $bits


id1296\BlindWatermark\WaterMark;
use Kid1296\BlindWatermark\Image\ImageIo;

$img = ImageIo::read('examples/pics/origin.jpg');
// $img = ['data'=>string, 'h'=>int, 'w'=>int, 'channels'=>int]

// embed — omit $filename, returns in-memory result array
$bwm1 = new WaterMark(1, 1);
$bwm1->read_img($img);                      // pass array directly
$bwm1->read_wm('This is a test sentence.', 'str');
$embedded = $bwm1->embed();                 // no filename → returns array
$lenWm = $bwm1->wmSize;
// $embedded is ['data'=>string, 'h'=>int, 'w'=>int, 'channels'=>int]
// You can save it with ImageIo::write(...) later, or stream to client.

// extract — pass embedImg array (instead of filename)
$bwm2 = new WaterMark(1, 1);
$extracted = $bwm2->extract(embedImg: $embedded, wmShape: $lenWm, mode: 'str');