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


PHP ImagickPixel isPixelSimilarQuantum()用法及代碼示例

ImagickPixel::isPixelSimilarQuantum()函數是PHP中的內置函數,用於檢查兩種顏色之間的距離是否小於指定的距離。模糊值應在0-65535的範圍內。此函數與isPixelSimilar()不同,因為它接受量子範圍內的模糊並實際上將一個像素與一種顏色進行比較,而不是與另一像素進行比較。

用法:

bool ImagickPixel::isPixelSimilarQuantum( string $color, string $fuzz )

參數:該函數接受上述和以下描述的兩個參數:


  • $color:它指定要比較的顏色。
  • $fuzz:它指定了模糊值。

返回值:該函數返回一個布爾值,該值表明它是否相似(真)或錯誤(假)。

異常:該函數在錯誤時引發ImagickException。

下麵給出的程序說明了PHP中的ImagickPixel::isPixelSimilarQuantum()函數:

程序1:

<?php 
// Create a new imagick object 
$imagickPixel = new ImagickPixel('green'); 
  
// Check if the pixel color is green 
$isSimilar = $imagickPixel->isPixelSimilarQuantum('green', 10); 
  
if ($isSimilar) { 
    echo 'Similar'; 
} else { 
    echo 'Not Similar'; 
} 
?>

輸出:

Similar

程序2:

<?php 
// Create a new imagick object 
$imagick = new Imagick( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Get the image histogram 
$histogramElements = $imagick->getImageHistogram(); 
  
// Get the 501th pixel 
$imagickPixel1 = $histogramElements[500]; 
  
// Check if the pixel color is red 
$isSimilar = $imagickPixel1->isPixelSimilarQuantum('red', 10); 
  
if ($isSimilar) { 
    echo 'Similar'; 
} else { 
    echo 'Not Similar'; 
} 
?>

輸出:

Not Similar

參考: https://www.php.net/manual/en/imagickpixel.ispixelsimilarquantum.php



相關用法


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