Imagick::evaluateImage()函數是PHP中的內置函數,用於將表達式應用於圖像。它可以將任何算術,邏輯或關係表達式應用於圖像並評估其結果。該操作員具有許多用途,從改變圖像的亮度,即使圖像變亮或變暗,或改變圖像的對比度或產生圖像的取反。
用法:
bool Imagick::evaluateImage( $evaluation_op, $constant, $channel = Imagick::CHANNEL_DEFAULT )
參數:此函數接受上述和以下所述的三個參數:
- $evaluation_op:它包含評估運算符,如加,減,除,mod等。
- $constant:它持有操作符的價值,並將與評估一起進行。
- $channel:它提供適合所需通道模式的任何通道常數。
返回值:如果函數成功執行,則返回布爾值true,否則返回false。
以下示例程序旨在說明PHP中的Imagick::evaluateImage()函數:
程序1:
<?php
// Create an Imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png');
// Declare and initialize the value of variable
$evaluation_op = Imagick::EVALUATE_DIVIDE;
$constant = 3;
$channel = Imagick::CHANNEL_ALPHA;
// Use evaluateImage function
$imagick->evaluateImage($evaluation_op, $constant, $channel);
header("Content-Type: image/jpg");
// Display the output image
echo $imagick->getImageBlob();
?>
輸出:
程序2:
<?php
// Creating new Imagick object
$image = new Imagick(__DIR__ . '\sample.png');
// Set the Alpha Channel to Opaque to facilitate Opaque operation
$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);
// Set the values of parameters
$evaluation_op = Imagick::EVALUATE_DIVIDE;
$constant = 3;
$channel = Imagick::CHANNEL_ALPHA;
// Calling the function with the parameters
$image->evaluateImage( $evaluation_op, $constant, $channel );
header('Content-type: image/jpeg');
// Writing the new image to specified directory
$image->writeImage(__DIR__ . '\sample_with_33perc_opacity.png');
?>
輸出:
程序3:
<?php
// Function definition
function Evaluate_Image( $image, $evaluation_op, $constant, $channel )
{
$image->evaluateImage( $evaluation_op, $constant, $channel );
return $image;
}
// Set values of the parameters
$final_image = Evaluate_Image(new Imagick(__DIR__ . '\sample.png'),
Imagick::EVALUATE_MEAN, 3, Imagick::CHANNEL_BLUE);
header('Content-type: image/jpeg');
// Display the output image
echo $final_image->getImageBlob();
?>
輸出:
參考: https://www.php.net/manual/en/imagick.evaluateimage.php
如果您發現問題或想添加更多信息,請發表評論。編碼愉快!!
相關用法
- PHP Imagick morphImages()用法及代碼示例
- PHP Imagick colorFloodfillImage()用法及代碼示例
- PHP Imagick levelImage()用法及代碼示例
- PHP Imagick linearStretchImage()用法及代碼示例
- PHP Imagick setImageDispose()用法及代碼示例
- PHP Imagick profileImage()用法及代碼示例
- PHP Imagick coalesceImages()用法及代碼示例
- PHP Imagick functionImage()用法及代碼示例
- PHP Imagick smushImages()用法及代碼示例
- PHP Imagick readImageBlob()用法及代碼示例
- PHP Imagick identifyFormat()用法及代碼示例
- PHP Imagick colorizeImage()用法及代碼示例
- PHP Imagick addImage()用法及代碼示例
- PHP Imagick clear()用法及代碼示例
- PHP Imagick getPage()用法及代碼示例
注:本文由純淨天空篩選整理自AllBoutStudies大神的英文原創作品 PHP | Imagick evaluateImage() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。