PHP Conference Japan 2024

Imagick::thresholdImage

(PECL imagick 2, PECL imagick 3)

Imagick::thresholdImage根據閾值變更個別像素的值

說明

public Imagick::thresholdImage(float $threshold, int $channel = Imagick::CHANNEL_DEFAULT): bool

根據每個像素的強度與閾值的比較,變更個別像素的值。結果是高對比的雙色影像。

參數

threshold

channel

回傳值

成功時回傳 true

範例

範例 #1 Imagick::thresholdImage()

<?php
function thresholdimage($imagePath, $threshold, $channel) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->thresholdimage($threshold * \Imagick::getQuantum(), $channel);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

新增註解

使用者貢獻的註解 1 則註解

1
php t traction dot de
12 年前
getQuantumRange() 在這裡可能很有用

<?php
$i
= new Imagick($imageFile);
$max = $i->getQuantumRange();
$max = $max["quantumRangeLong"];
$i->thresholdImage(0.77 * $max);
?>
To Top