Dutch PHP Conference 2025 - Call For Papers

Imagick::transparentPaintImage

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

Imagick::transparentPaintImagePaints pixels transparent

Опис

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

Paints pixels matching the target color transparent. Цей метод доступний, якщо Imagick зібраний з ImageMagick версії 6.3.8 або новішою.

Параметри

target

The target color to paint

alpha

Рівень прозорості: 1.0 — непрозорий і 0.0 — повністю прозорий.

fuzz

Міра уподібнення кольорів. Наприклад, якщо значення fuzz дорівнює 10, то червоний колір з насиченістю від 100 до 102 тепер вважатиметься одним кольором.

invert

If true paints any pixel that does not match the target color.

Значення, що повертаються

Повертає true в разі успіху.

Приклади

Приклад #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
6 months 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)".
To Top