查詢

Imagick::thresholdImage()函式—用法及示例

「 基於閾值更改單個畫素的值 」


函式名: Imagick::thresholdImage()

適用版本: Imagick 類在 Imagick 擴充套件版本 3.1.0 或更高版本中可用。

用法: Imagick::thresholdImage(float $threshold [, int $channel = Imagick::CHANNEL_DEFAULT])

引數:

  1. $threshold:閾值,取值範圍為0到QuantumRange。
  2. $channel(可選):通道常量,指定要應用閾值的通道。預設為 Imagick::CHANNEL_DEFAULT,表示應用於所有通道。

返回值:成功時返回 true。

示例:

// 建立 Imagick 物件
$image = new Imagick('image.jpg');

// 應用閾值濾鏡
$thresholdValue = 0.5;
$image->thresholdImage($thresholdValue);

// 顯示處理後的影象
header('Content-Type: image/jpeg');
echo $image;

在上述示例中,我們首先建立了一個 Imagick 物件,載入了一個名為 "image.jpg" 的影象檔案。然後,我們呼叫 thresholdImage() 方法,並傳入閾值引數。在本例中,我們將閾值設定為 0.5。最後,我們使用 header() 函式將影象的 MIME 型別設定為 image/jpeg,並輸出處理後的影象。

請注意,此示例僅演示瞭如何使用 thresholdImage() 方法。你可以根據自己的需求進行更多的影象處理操作,例如調整影象大小、應用濾鏡等。

補充糾錯
上一個函式: Imagick::thumbnailImage()函式
下一個函式: Imagick::swirlImage()函式
熱門PHP函式
分享連結