Open In App

PHP | Imagick removeImage() Function

The Imagick::removeImage() function is an inbuilt function in PHP which is used to remove an image from the image list. This function removes the current image which is pointed by the cursor.

Syntax:



bool Imagick::removeImage( void )

Parameters: This function doesn’t accepts any parameters.

Return Value: This function returns TRUE on success.



Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::removeImage() function in PHP:

Program 1:




<?php
  
// Create a new Imagick object
$imagick = new Imagick(
  
// Count the image
echo 'Number of images before removing: '. $imagick->count() . '<br>';
  
// Remove the Image
$imagick->removeImage();
  
// Count the image
echo 'Number of images after removing: '. $imagick->count();;
?>

Output:

Number of images before removing: 1
Number of images after removing: 0

Program 2:




<?php
  
// Create a new Imagick object
$imagick = new Imagick(
  
// Add a new image to Imagick object
$imagick->addImage(new Imagick(
  
// Count the image
echo 'Number of images before removing: '. $imagick->count() . '<br>';
  
// Remove the Image
$imagick->removeImage();
  
// Count the image
echo 'Number of images after removing: '. $imagick->count();;
?>

Output:

Number of images before removing: 2
Number of images after removing: 1

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


Article Tags :