Friday, August 29, 2025
HomeLanguagesPHP | Imagick hasPreviousImage() Function

PHP | Imagick hasPreviousImage() Function

The Imagick::hasPreviousImage() function is an inbuilt function in PHP which is used to check whether the Imagick object is having a previous image or not. If Imagick object has multiple images it returns true else it returns false.
Syntax: 
 

bool Imagick::hasPreviousImage( void )

Parameters: This function does not accepts any parameters.
Return Value: This function returns TRUE if the object has more images when traversing the list in the reverse direction, otherwise returns FALSE.
Below program illustrates the Imagick::hasPreviousImage() function in PHP:
Program: This program demonstrate the working of hasPreviousImage() function with multiple images and without multiple images. 
 

php




<?php
 
// String array containing path of images
$imagePaths = [
];
 
// Create new Imagick object
$canvas = new Imagick();
 
$image = new Imagick(
 
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 !!');
}
 
?>


Output: 
 

$canvas has Multiple Images !!

Reference: https://www.php.net/manual/en/imagick.haspreviousimage.php
 

RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11791 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7012 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS