PHP | Imagick steganoImage() Function

The ImagickDraw::steganoImage() function is an inbuilt function in PHP which is used to hide a digital watermark within the image. Watermark can be a simple text or image too. Usually, colorful images get distorted with this. The hidden watermark can be recovered later to prove the authenticity of an image. Offset defines the start position within the image to hide the watermark. While recovering the image offset is required.

Syntax:

Imagick ImagickDraw::steganoImage( Imagick $watermark_wand, int $offset )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $watermark_wand: It specifies the secret watermark wand.
  • $offset: It specifies the secret offset to be used to recover watermark band.

Return Value: This function returns an Imagick object containing the watermarked image.

Exceptions: This function throws ImagickException on error.



Below programs illustrate the ImagickDraw::steganoImage() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Create another Imagick object containing watermark
$watermark = new Imagick('label:This is my secret.');
  
// Hide $watermark inside $imagick
$imagick = $imagick->steganoImage($watermark, 64);
  
// Write image to the local folder
$imagick->writeImage('output.png');
  
// Set the offset
$imagick->setSizeOffset($watermark->getImageWidth(),
                   $watermark->getImageHeight(), 64);
  
// Read the encoded image and extract secret
$imagick->readImage('STEGANO:output.png');
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Create another Imagick object containing a secret image
$watermark = new Imagick(
  
// Hide $watermark inside $imagick
$imagick = $imagick->steganoImage($watermark, 10);
  
// Write image to the local folder
$imagick->writeImage('output.png');
  
// Set the offset
$imagick->setSizeOffset($watermark->getImageWidth(),
                   $watermark->getImageHeight(), 10);
  
// Read the encoded image and extract secret
$imagick->readImage('STEGANO:output.png');
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagick.steganoimage.php




My Personal Notes arrow_drop_up

I love Open Source Culture have contributed to phpMyAdmin, LibreOffice, Ant-Design and Web is my passion

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.