Open In App

PHP | Imagick remapImage() Function

The Imagick::remapImage() function is an inbuilt function in PHP which is used to replace colors in an image with those defined by replacement. The colors are replaced with the closest possible color.

Syntax:



bool Imagick::remapImage( Imagick $replacement, int $dither )

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

List of all DITHERMETHOD constants are given below:



Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

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

Program 1:




<?php
  
// Create a new Imagick object
$imagick = new Imagick(
  
// Create another Imagick object
$replacement = new Imagick(
  
// Remap the image
$imagick->remapImage($replacement, imagick::DITHERMETHOD_RIEMERSMA);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output:

Program 2:




<?php
  
// Create a new Imagick object
$imagick = new Imagick(
  
// Create another Imagick object
$replacement = new Imagick(
  
// Remap the image
$imagick->remapImage($replacement, imagick::DITHERMETHOD_FLOYDSTEINBERG);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output:

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


Article Tags :