Thursday, December 25, 2025
HomeLanguagesPHP | Gmagick readimage() Function

PHP | Gmagick readimage() Function

The Gmagick::readimage() function is an inbuilt function in PHP which is used to read an image from your local folder and add it to the Gmagick object. This is an alternative to read() function.

Syntax:

Gmagick Gmagick::readimage( string $filename )

Parameters: This function accepts a single parameter $filename which holds the name of the file.

Return Value: This function returns a Gmagick object containing the image.

Exceptions: This function throws GmagickException on error.

Below given programs illustrate the Gmagick::readimage() function in PHP:

Used Image:

Program 1 (Reading image from folder):




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick();
  
// Read an image
$gmagick->readimage('neveropen.png');
  
// Output the image  
header('Content-type: image/png');  
echo $gmagick;  
?>


Output:

Program 2 (Editing image after reading):




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick();
  
// Read an image
$gmagick->readimage('neveropen.png');
  
// Here you can further work with your loaded image
  
// Simulate a charcoal drawing
$gmagick->charcoalimage(0.1, 10);
  
// Output the image
header('Content-type: image/png');
echo $gmagick;
?>


Output:

Reference: https://www.php.net/manual/en/gmagick.readimage.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32456 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6825 POSTS0 COMMENTS
Nicole Veronica
11960 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6959 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6912 POSTS0 COMMENTS
Umr Jansen
6893 POSTS0 COMMENTS