Skip to content
Related Articles

Related Articles

PHP | Imagick remapImage() Function

Improve Article
Save Article
  • Last Updated : 04 Dec, 2019
Improve Article
Save Article

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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!