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.


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.





// String array containg path of images
$imagePaths = [
// Create new Imagick object
$canvas = new Imagick();
$image = new Imagick(
foreach ($imagePaths as $imagePath) {
    // Adding images in the canvas
// 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 !!


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.