Imagick::transparentPaintImage

(PECL imagick 2 >= 2.3.0, PECL imagick 3)

Imagick::transparentPaintImage — Pinta píxeles transparentes

Descripción

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

Pinta píxeles transparente que coincidan con el color objetivo. Este método solo está disponible si Imagick ha sido compilado con ImageMagick versión 6.3.8 o superior.

Parámetros

target

El color objetivo a pintar

alpha

El grado de transparencia: 1.0 corresponde a totalmente opaco y 0.0 a totalmente transparente.

fuzz

La cantidad de fuzz. Por ejemplo, si se define fuzz en 10, el color rojo con intensidades de 100 y 102, respectivamente, se interpretará ahora como el mismo color.

invert

Si es true pinta cualquier píxel que no coincida con el color objetivo.

Valores devueltos

Devuelve true en caso de éxito.

Ejemplos

Ejemplo #1 Imagick::transparentPaintImage()

<?php
function transparentPaintImage($color, $alpha, $fuzz) {
    $imagick = new \Imagick(realpath("images/BlueScreen.jpg"));

    //Need to be in a format that supports transparency
    $imagick->setimageformat('png');

    $imagick->transparentPaintImage(
        $color, $alpha, $fuzz * \Imagick::getQuantum(), false
    );

    //Not required, but helps tidy up left over pixels
    $imagick->despeckleimage();

    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}

?>
+add a note

User Contributed Notes 1 note

up
1
josecarlosphp
2 years ago
The $color parameter can be a string like this:

"rgb(255, 255, 255)"

As you can guess, that example represents white color.
"rgb" indicates red-green-blue, and numeric values are amounts for each, from 0 to 255.

Black color it will be "rgb(0, 0, 0)".
Full red color it will be "rgb(255, 0, 0)".