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:
- $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
$imagick = new Imagick(
$replacement = new Imagick(
$imagick ->remapImage( $replacement , imagick::DITHERMETHOD_RIEMERSMA);
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick(
$replacement = new Imagick(
$imagick ->remapImage( $replacement , imagick::DITHERMETHOD_FLOYDSTEINBERG);
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
Share your thoughts in the comments
Please Login to comment...