Thursday, October 9, 2025
HomeLanguagesPHP | Imagick readImageFile() Function

PHP | Imagick readImageFile() Function

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
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a file handle
$handle = fopen(
  
// Read the image
$imagick->readImageFile($handle);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a file handle
$handle = fopen(
'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

RELATED ARTICLES

Most Popular

Dominic
32346 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11940 POSTS0 COMMENTS
Shaida Kate Naidoo
6835 POSTS0 COMMENTS
Ted Musemwa
7095 POSTS0 COMMENTS
Thapelo Manthata
6790 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS