Open In App

PHP | Imagick readImageFile() Function

Last Updated : 04 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The Imagick::readImageFile() function is an inbuilt function in PHP which is used to read image from open filehandle. Syntax:
bool Imagick::readImageFile( resource $filename, string $fileName = NULL )
Parameters:This function accepts two parameters as mentioned above and described below:
  • $filehandle: It specifies the file handle.
  • $fileName: It specifies the name of file.
Return Value: This function returns TRUE on success. Exceptions: This function throws ImagickException on error. Below programs illustrate the Imagick::readImageFile() function in PHP: Program 1: php
<?php

// Create a new imagick object
$imagick = new Imagick();

// Create a file handle
$handle = fopen(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png', 'rgb');

// Read the image
$imagick->readImageFile($handle);

// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
Output: Program 2: php
<?php

// Create a new imagick object
$imagick = new Imagick();

// Create a file handle
$handle = fopen(
'https://media.geeksforgeeks.org/wp-content/uploads/20191117194549/g4ganimatedcolor.gif',
'rgb');

// Read the image
$imagick->readImageFile($handle);

// Display the image
header("Content-Type: image/gif");
echo $imagick->getImagesBlob();
?>
Output: Reference: https://www.php.net/manual/en/imagick.readimagefile.php

Next Article

Similar Reads