PHP | Gmagick readimageblob() Function
Last Updated :
14 Jan, 2020
The Gmagick::readimageblob() function is an inbuilt function in PHP which is used to read image from a binary string. This string is called blob, thus the name readimageblob. Further an image can be converted into a string using getimageblob() function.
Syntax:
Gmagick Gmagick::readimageblob( string $imageContents, string $filename )
Parameters: This function accept two parameters as mentioned above and described below:
- $imageContents: It specifies the binary image content.
- $filename: It specifies the name to be given to 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::readimageblob() function in PHP:
Used Image:
Program 1 (Reading a image from string(blob)):
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$imageAsString = $gmagick ->getimageblob();
$gmagickNew = new Gmagick();
$gmagickNew ->readimageblob( $imageAsString , 'mygeeksforgeeks.png' );
header( 'Content-type: image/png' );
echo $gmagickNew ;
?>
|
Output:
Program 2 (Further editing image after reading):
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$imageAsString = $gmagick ->getimageblob();
$gmagickNew = new Gmagick();
$gmagickNew ->readimageblob( $imageAsString ,
'myembossedgeeksforgeeks.png' );
$gmagickNew ->embossimage(30, 20);
header( 'Content-type: image/png' );
echo $gmagickNew ;
?>
|
Output:
Reference: https://www.php.net/manual/en/gmagick.readimageblob.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...