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


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

Imagick::hasPreviousImage()函數是PHP中的內置函數,用於檢查Imagick對象是否具有先前的圖像。如果Imagick對象具有多個圖像,則返回true,否則返回false。

用法:

bool Imagick::hasPreviousImage( void )

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


返回值:如果對象在反向移動列表時具有更多圖像,則此函數返回TRUE,否則返回FALSE。

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

程序:該程序演示了hasPreviousImage()函數在多幅圖像和無多幅圖像的情況下的工作原理。

<?php 
  
// String array containg path of images 
$imagePaths = [ 
"https://www.geeksforgeeks.org/wp-content/uploads/gfg_200X200.png", 
"https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-6.png"
]; 
  
// Create new Imagick object 
$canvas = new Imagick(); 
  
$image = new Imagick( 
'https://www.geeksforgeeks.org/wp-content/uploads/gfg_200X200.png'); 
  
foreach ($imagePaths as $imagePath) { 
      
    // Adding images in the canvas 
    $canvas->readImage($imagePath); 
} 
  
// The pointer points to second image 
if($canvas->hasPreviousImage()) { 
    echo('$canvas has Multiple Images !!'); 
} 
  
if($image->hasPreviousImage()) { 
      
    // With a single image 
    echo('$image has Multiple Images !!'); 
} 
  
?>

輸出:

$canvas has Multiple Images !!

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



相關用法


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