Skip to content
Related Articles

Related Articles

Improve Article

PHP | Imagick transparentPaintImage() Function

  • Last Updated : 14 Oct, 2019

The Imagick::transparentPaintImage() function is an inbuilt function in PHP which Paints pixels transparent. Paints pixels matching the target color transparent. This method is available if Imagick has been compiled against ImageMagick version 6.3.8 or above.


bool Imagick::transparentPaintImage ( mixed $target, float $alpha, float $fuzz, bool $invert )

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

  • $target: The target color to paint transparent.
  • $alpha: The range of transparency: 1.0 is fully opaque and 0.0 is fully transparent.
  • $fuzz: If TRUE paints any pixel that does not match the target color.
  • $invert: The image whitePoint.
    Return Value: This function returns True on success.

Below program illustrates the Imagick::transparentPaintImage() function in PHP:


$color="rgb(39, 194, 255)";
$imagick = new \Imagick(realpath($source));
    //Need to be in a format that supports transparency
        $color, $alpha, $fuzz * \Imagick::getQuantum(), $inverse
    //Not required, but helps tidy up left over pixels
    $canvas = new Imagick();
    $canvas->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, 0);
    header("Content-Type: image/png");
    echo $canvas->getImageBlob();



My Personal Notes arrow_drop_up
Recommended Articles
Page :