PHP Conference Japan 2024

Imagick::solarizeImage

(PECL imagick 2, PECL imagick 3)

Imagick::solarizeImage對影像套用曝光效果

說明

public Imagick::solarizeImage(int $threshold): bool

對影像套用特殊效果,類似於在暗房中透過選擇性地將感光紙的區域曝光於光線而達到的效果。閾值範圍從 0 到 QuantumRange,是用於衡量曝光程度的指標。

參數

threshold (閾值)

傳回值

成功時傳回 true

範例

範例 #1 Imagick::solarizeImage()

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

?>

新增註解

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

holdoffhunger at gmail dot com
12 年前
這是一個您可以對影像執行的巧妙操作,作為藝術化處理的一部分,可能與其他 ImageMagick 效果(例如 PosterizeImage 和 OilPaintImage)結合使用。 SolarizeImage 會將影像的整個色譜向紅色偏移——白色直接推到紅色,藍色推到綠色,等等。這主要是一種迷幻效果。「閾值」參數可選,它實際上只是您希望在影像中呈現多少這種效果。最小值為 0,使用負數則預設為 0。最大值為量子閾值。您可以透過 ImageMagick 函式 getQuantumRange 取得此值。在我的 PHP 安裝中,該值設定為 65535 (2^16)。高於量子範圍的值會預設為量子範圍。使用此函式處理且閾值為 0 的影像會產生最大效果,而閾值為最大值的影像則完全沒有任何變化。

現在是一個簡單的程式碼示範

<?php

// 作者:holdoffhunger@gmail.com

// 取得影像檔案資料
// ---------------------------------------------

$file_to_grab_with_location = "graphics_engine/image_workshop_directory/test.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->solarizeImage(30000);

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

$file_to_save_with_location = "graphics_engine/image_workshop_directory/test_new.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