Search code examples
phpimage-processingimagemagickimagick

how to restore the watermark set with Imagick::steganoImage()


So I used this Imagemagick library wrapper written in PHP and came to know about this function called steganoImage() which simply says that it will hide a watermark inside the image. But problem is documentation doesn't state how to restore that image back. I checked all the other functions too, didn't find anything. I would like to have an Imagick solution for this.


Solution

  • The answer provided by Bonzo is correct. An example in PHP's Imagick would look very similar.

    $image = new Imagick('rose:');
    $watermark = new Imagick('label:Hello World!');
    
    // The decoding process must "know" about the watermarks size, and starting
    // pixel offset.
    define('STEGANO_OFFSET', 64); // Secret offset
    define('STEGANO_WIDTH', $watermark->getImageWidth());
    define('STEGANO_HEIGHT', $watermark->getImageHeight());
    
    $stegano = $image->steganoImage($watermark, STEGANO_OFFSET);
    $stegano->writeImage('output.png');
    

    output.png

    To decode the original watermark, define the width, height, and offset of the hidden image before reading the file.

    $decoded = new Imagick();
    $decoded->setSizeOffset(STEGANO_WIDTH, STEGANO_HEIGHT, STEGANO_OFFSET);
    $decoded->readImage('STEGANO:output.png');
    $decoded->writeImage('decoded.png');
    

    decoded.png