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


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

ImagickPixel::getIndex()函數是PHP中的內置函數,用於獲取像素的顏色圖索引。

用法:

int ImagickPixel::getIndex( void )

參數:此函數不接受任何參數。


返回值:該函數返回一個包含索引的整數值。

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

下麵給出的程序說明了PHP:程序1中的ImagickPixel::getIndex()函數:程序1(獲取單個像素的索引):

<?php 
// Create a new imagickPixel object 
$imagickPixel = new ImagickPixel(); 
  
// Get the index 
$index = $imagickPixel->getIndex(); 
echo $index; 
?>

輸出:

0 // which is the default index for a pixel.

程序2(獲取圖像所有像素的索引):

<?php 
// Create a new imagickPixel object 
$imagickPixel = new ImagickPixel(); 
  
// Set the index 
$imagickPixel->setIndex(5); 
  
// Get the index 
$index = $imagickPixel->getIndex(); 
echo $index; 
?>

輸出:

5

程序3:

<?php 
// Create a new imagick object 
$imagick = new Imagick( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Get the pixel iterator to iterate through each pixel 
$imageIterator = $imagick->getPixelIterator(); 
  
// Loop through pixel rows 
foreach ($imageIterator as $row => $pixels) { 
  
    foreach ($pixels as $column => $pixel) { 
        // Get the index of each pixel of image 
        echo $pixel->getindex() . '<br>'; 
  
    } 
  
    // Sync the iterator after each iteration 
    $imageIterator->syncIterator(); 
} 
?>

輸出:

0
0
0
0
.
.
.

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



相關用法


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