Open In App

PHP | Imagick remapImage() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • $replacement: It specifies an Imagick object containing the replacement colors.
  • $dither: It specifies an integer value corresponding to one of DITHERMETHOD constants. You can also pass constant directly like remapImage($replacement, imagick::DITHERMETHOD_RIEMERSMA);.

List of all DITHERMETHOD constants are given below:

  • imagick::DITHERMETHOD_UNDEFINED (0)
  • imagick::DITHERMETHOD_NO (1)
  • imagick::DITHERMETHOD_RIEMERSMA (2)
  • imagick::DITHERMETHOD_FLOYDSTEINBERG (3)

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



Last Updated : 04 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads