Friday, January 10, 2025
Google search engine
HomeLanguagesPHP | Imagick mapImage() Function

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:

  • $map: This parameter holds the Imagick object.
  • $dither: This parameter holds a boolean which decides whether to add noise or not.

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments