Open In App

PHP | Imagick mapImage() Function

The Imagick::mapImage() function is an inbuilt function in PHP which is used to replace the colors of an image with the closest color from a reference image.

Syntax:



bool Imagick::mapImage( Imagick $map, float $dither )

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

Return Value: This function returns TRUE on success.



Errors/Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::mapImage() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick1 = new Imagick(
   
// Create another imagick object
$imagick2 = new Imagick(
   
// Mapping the image with noise
$imagick1->mapImage($imagick2, true);
   
header("Content-Type: image/jpg"); 
     
// Display the output image 
echo $imagick1->getImageBlob();
  
?>

Output:

Program 2:




<?php
  
// Create a new imagick object
$imagick1 = new Imagick(
   
// Create another imagick object
$imagick2 = new Imagick(
   
// Mapping the image without noise
$imagick1->mapImage($imagick2, false);
   
header("Content-Type: image/jpg"); 
     
// Display the output image 
echo $imagick1->getImageBlob();
  
?>

Output:

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


Article Tags :