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):

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Program 2 (Editing image after reading):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick();
  
// Read an image
$gmagick->readimage('geeksforgeeks.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;
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/gmagick.readimage.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.