当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。