PHP 8.3.4 Released!

Imagick::transparentPaintImage

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

Imagick::transparentPaintImageピクセルを透過させる

説明

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

対処の色にマッチするピクセルを透過させます。 このメソッドは、ImageMagick バージョン 6.3.8 以降で Imagick をコンパイルした場合に使用可能です。

パラメータ

target

対象となる色。

alpha

透明度。1.0 は完全な不透明で 0.0 が完全な透明をあらわします。

fuzz

あいまいさをあらわす量。たとえば、これを 10 に設定すると、 赤色の値が 100 の色と 102 の色は同じものとみなされます。

invert

true の場合は、対象の色にマッチしないピクセルを変更します。

戻り値

成功した場合に 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
0
josecarlosphp
26 days 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