PHP | Imagick readImages() Function

The Imagick::readImages() function is an inbuilt function in PHP which is used to read images from an array of filenames and associate them to a single Imagick object.

Syntax:

bool Imagick::readImages( array $filenames )

Parameters:This function accepts a single parameter $filenames which holds an array containing all the filenames.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.



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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Array of images
$images = [
];
  
// Read the images
$imagick->readImages($images);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Array of images
$images = [
];
  
// Read the images
$imagick->readImages($images);
  
// Moving index to 0 to check if the first image
// is also inserted.
$imagick->setIteratorIndex(0);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Array of images (from local folder). For this
// to work mentioned images should be there in the
// local folder.
$images = [
    'filename1.png',
    'filename2.png'
];
  
// Read the images
$imagick->readImages($images);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

It will show filename2.png on the screen.

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




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 contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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 contribute@geeksforgeeks.org to report any issue with the above content.