PHP 8.3.4 Released!

Imagick::blackThresholdImage

(PECL imagick 2, PECL imagick 3)

Imagick::blackThresholdImage閾値に満たないすべてのピクセルを黒にする

説明

public Imagick::blackThresholdImage(mixed $threshold): bool

Imagick::thresholdImage() と似ていますが、 これは閾値に満たないピクセルをすべて黒にし、その他のピクセルはそのままにします。

パラメータ

threshold

すべて黒にする閾値。

戻り値

成功した場合に true を返します。

変更履歴

バージョン 説明
PECL imagick 2.1.0 色を表す文字列をパラメータとして指定できるようになりました。 これまでのバージョンでは ImagickPixel オブジェクトしか指定できませんでした。

例1 Imagick::blackThresholdImage()

<?php
function blackThresholdImage($imagePath, $thresholdColor) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->blackthresholdimage($thresholdColor);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

add a note

User Contributed Notes 2 notes

up
4
Iddles
12 years ago
You need to pass this function a colour:

<?php

$img
->blackThresholdImage( "#FFFFFF" );

?>

E.g. this blackens any pixel which isn't pure white.
up
1
elmer at web-axis dot net
15 years ago
Here's a example of this function:

<?php
$img
= new Imagick();
$img->readImage($image_file_name);
$img->blackThresholdImage('grey');
$img->writeImage($thumb_file_name);
$img->clear();
$img->destroy();
?>
To Top