Open In App

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:

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:




<?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();
?>

Output:

Program 2:




<?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();
?>

Output:

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


Article Tags :