當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP Imagick contrastStretchImage()用法及代碼示例

Imagick::contrastStretchImage()函數是PHP中的內置函數,用於增強圖像的對比度。此函數通過調整像素顏色以覆蓋可用顏色的整個範圍來增強彩色圖像的對比度。

用法:

bool Imagick::contrastStretchImage( float $black_point,
         float $white_point, int $channel = Imagick::CHANNEL_DEFAULT)

參數:此函數接受上述和以下所述的三個參數:


  • $black_point:此參數保留黑點。
  • $white_point:此參數保留白點。
  • $channel:該參數保存Imagick通道常數,該常數提供對通道模式有效的任何通道常數。可以使用按位運算符組合多個通道。通道常數的默認值為CHANNEL_DEFAULT。

返回值:成功時此函數返回TRUE。

以下示例程序旨在說明PHP中的Imagick::contrastStretchImage()函數:

程序1:

<?php 
  
// Create new Imagick object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png'); 
  
// Apply the contrastStretchImage() function 
$imagick->contrastStretchImage(10, 20); 
  
header("Content-Type: image/png"); 
  
// Display the output image 
echo $imagick->getImageBlob(); 
?>

輸出:

程序2:

<?php 
  
// Create new Imagick object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png'); 
  
// Apply the contrastStretchImage() function 
$imagick->contrastStretchImage(100, 50); 
  
header("Content-Type: image/png"); 
  
// Display the output image 
echo $imagick->getImageBlob(); 
?>

輸出:

程序3:

<?php 
  
// Create new Imagick object 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png'); 
  
// Apply the contrastStretchImage() function 
$imagick->contrastStretchImage(5000, 100); 
  
header("Content-Type: image/png"); 
  
// Display the output image 
echo $imagick->getImageBlob(); 
?>

輸出:

參考: https://www.php.net/manual/en/imagick.contraststretchimage.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | Imagick contrastStretchImage() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。