PHP | Gmagick readimageblob() Function

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   // Create a new Gmagick object $gmagick = new Gmagick('zambiatek.png');   // Convert image into string $imageAsString = $gmagick->getimageblob();   // Create new Gmagick object $gmagickNew = new Gmagick();   // Read image from string $gmagickNew->readimageblob($imageAsString, 'myzambiatek.png');   // Output the image header('Content-type: image/png'); echo $gmagickNew; ?> |
Output:
Program 2 (Further editing image after reading):
<?php   // Create a new Gmagick object $gmagick = new Gmagick('zambiatek.png');   // Convert image into string $imageAsString = $gmagick->getimageblob();   // Create new Gmagick object $gmagickNew = new Gmagick();   // Read image from string $gmagickNew->readimageblob($imageAsString,             'myembossedzambiatek.png');   // Here you can further edit your // loaded image as given below   // Emboss the image $gmagickNew->embossimage(30, 20);   // Output the image header('Content-type: image/png'); echo $gmagickNew; ?> |
Output:
Reference: https://www.php.net/manual/en/gmagick.readimageblob.php




