Thursday, May 14, 2026
HomeLanguagesPHP | Imagick previousImage() Function

PHP | Imagick previousImage() Function

The Imagick::previousImage() function is an inbuilt function in PHP which is used to move to the previous image within the Imagick instance. An Imagick instance may consist of a list of images within it and Imagick previousImage() moves the pointer/cursor to the previous image in the image list within an Imagick instance.

Syntax:

bool Imagick::previousImage( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the Imagick::previousImage() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Add a image to the imagick object.
$imagick->addImage(new Imagick(
  
// Get the index
$index1 = $imagick->getIteratorIndex();
echo 'Before: ' . $index1 . '<br>';
  
// Move the cursor to first image
$imagick->previousImage();
$imagick->previousImage();
  
// Get the index
$index2 = $imagick->getIteratorIndex();
echo 'After: ' . $index2 . '<br>';
?>


Output:

Before: 1
After: 0

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Add a image to the imagick object.
$imagick->addImage(new Imagick(
  
// Move the cursor to first image
$imagick->previousImage();
$imagick->previousImage();
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS