Open In App

PHP | Imagick sparseColorImage() Function

The Imagick::sparseColorImage() function is an inbuilt function in PHP which is used to interpolate the colors across the whole image.

Syntax:



bool Imagick::sparseColorImage( int $SPARSE_METHOD, array $arguments, int $channel )

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

Return Value: This function returns TRUE on success.



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

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
$array = array(0, 0, 1, 0, 0, 1, 900, 0, 0, 1,
               0, 1, 0, 1, 100, 1, 0, 70, 400,
               90, 0, 0, 1, 1);
  
// Apply the sparseColorImage() function
$imagick->sparseColorImage(imagick::SPARSECOLORMETHOD_BILINEAR, $array);
  
// Show the output
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output:

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
$array = array(0, 0, 1, 0, 0, 1, 78, 0, 0, 1,
               0, 1, 0, 1, 10, 1, 0, 20, 400,
               90, 0, 0, 1, 1);
  
// Apply the sparseColorImage() function
$imagick->sparseColorImage(imagick::SPARSECOLORMETHOD_BARYCENTRIC, $array);
  
// Show the output
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output:

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


Article Tags :