Skip to content
Related Articles

Related Articles

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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;
?>

chevron_right


Output:

Program 2 (Further editing image after reading):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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;
?>

chevron_right


Output:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :