PHP Conference Japan 2024

Imagick::orderedPosterizeImage

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

Imagick::orderedPosterizeImage執行有序的抖色

警告

此函數自 Imagick 3.4.4 起已過時。 強烈建議不要依賴此函數。

描述

public Imagick::orderedPosterizeImage(string $threshold_map, int $channel = Imagick::CHANNEL_DEFAULT): bool

根據一些預先定義的抖色臨界值對應執行有序抖色,但根據輸入參數,在多個強度級別上執行,這些強度級別對於不同的通道可能不同。 如果 Imagick 是針對 ImageMagick 6.3.1 或更新版本編譯的,則可以使用此方法。

參數

threshold_map

一個字串,其中包含要使用的臨界值抖動對應的名稱

channel

提供對您的通道模式有效的任何通道常數。 若要套用至多個通道,請使用位元運算子組合 channeltype 常數。 請參閱此通道常數清單。

傳回值

成功時傳回 true

錯誤/例外狀況

發生錯誤時擲回 ImagickException。

範例

範例 #1 Imagick::orderedPosterizeImage()

<?php
function orderedPosterizeImage($imagePath, $orderedPosterizeType) {
$imagick = new \Imagick(realpath($imagePath));


$imagick->orderedPosterizeImage($orderedPosterizeType);
$imagick->setImageFormat('png');

header("Content-Type: image/png");
echo
$imagick->getImageBlob();
}

//orderedPosterizeImage($imagePath, 'o4x4,3,3');
//orderedPosterizeImage($imagePath, 'o8x8,6,6');
orderedPosterizeImage($imagePath, 'h8x8a');





?>

新增註解

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

0
holdoffhunger at gmail dot com
12 年前
最初,我認為這個函數會與 Posterize 函數類似,或至少是任何產生藝術效果的 Imagick 類別函數(例如油彩繪圖函數)。這個函數可用於這些目的,但它主要用於印刷生產。OrderedPosterize 只是高度靈活的抖色工具。其目的本質上是透過在介質上使用根據影像細節而尺寸不同的恆定點來產生高解析度影像。每個人都曾在報紙上看到抖色的照片,但 wiki 頁面提供了更好的範例:http://en.wikipedia.org/wiki/Dither

對於只想使用此函數而不必太在意 Imagick 類別的人來說,這兩個參數很不尋常。

第一個參數:threshold_map 是一組由非常簡單的 xml 檔案預先定義的「筆刷」。它們是:threshold、checks、o2x2、o3x3、o4x4、o8x8、h4x4a、h6x6a、h8x8a、h4x4o、h6x6o、h8x8o、h16x16o、c5x5b、c5x5w、c6x6b、c6x6w、c7x7b 和 c7x7w。這些是您預期輸入作為 Thershold_Map 值的參數。Imagick 網站上提供了這些筆刷形狀的更好描述:https://imagemagick.dev.org.tw/Usage/quantize/tmaps_list.txt

第二個參數:通道是 Imagick 類別預先定義的任何常數。在程式碼中,該值看起來像 "imagick::CHANNEL_RED",但您有 "_value" 選項:red、undefined、gray、cyan、green、magenta、blue、yellow、alpha、opacity、matte、black、index、all 和 default。更多資訊在此處: https://php.dev.org.tw/manual/en/imagick.constants.php#imagick.constants.channel

最後,別忘了您可以在第二個參數上使用位元運算子。這表示您可以使用 & 來進行 AND 運算,| 來進行 OR 運算,& 來進行 XOR 運算,以及 ~ 來進行 NEGATE 運算。第二個參數的有效參數為:"((~imagick::CHANNEL_GREEN) ^ imagick::CHANNEL_YELLOW) | imagick::CHANNEL_MAGENTA)"。您可以在這個特定參數中獲得極大的創造力。如果您想使用簡單的 XML 定義自己的筆刷,那麼第一個參數也是如此。

注意:您可以藝術地使用此函數。如何?使用 orderedPosterizeImage 為影像提供一些紋理(例如,花瓶的照片),然後使用 OilPoint、Sketch 或標準 Posterize 為影像提供酷炫效果。不過,單獨使用似乎很無聊。

現在,進行一個非常簡單的演示

<?php

// 作者:holdoffhunger@gmail.com

// 檔案名稱
// ---------------------------------------------

$file_to_grab_with_location = "graphics_engine/image_workshop_directory/ordered_posterize_source.bmp"

$imagick_type = new Imagick();

// 開啟檔案
// ---------------------------------------------

$file_handle_for_viewing_image_file = fopen($file_to_grab_with_location, 'a+');

$imagick_type->readImageFile($file_handle_for_viewing_image_file);

// 執行函數
// ---------------------------------------------

$imagick_type->orderedPosterizeImage("o2x2", imagick::CHANNEL_GREEN);

// 儲存檔案
// ---------------------------------------------

$file_to_save_with_location = "graphics_engine/image_workshop_directory/ordered_posterize_result.bmp"

$file_handle_for_saving_image_file = fopen($file_to_save_with_location, 'a+');

$imagick_type->writeImageFile($file_handle_for_saving_image_file);

?>
To Top