Open In App

PHP | Gmagick readimageblob() Function

Last Updated : 14 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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('geeksforgeeks.png');
  
// Convert image into string
$imageAsString = $gmagick->getimageblob();
  
// Create new Gmagick object
$gmagickNew = new Gmagick();
  
// Read image from string
$gmagickNew->readimageblob($imageAsString, 'mygeeksforgeeks.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('geeksforgeeks.png');
  
// Convert image into string
$imageAsString = $gmagick->getimageblob();
  
// Create new Gmagick object
$gmagickNew = new Gmagick();
  
// Read image from string
$gmagickNew->readimageblob($imageAsString,
            'myembossedgeeksforgeeks.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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads