Friday, August 15, 2025
HomeLanguagesPHP | Gmagick readimageblob() Function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32221 POSTS0 COMMENTS
Milvus
76 POSTS0 COMMENTS
Nango Kala
6594 POSTS0 COMMENTS
Nicole Veronica
11758 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11806 POSTS0 COMMENTS
Shaida Kate Naidoo
6701 POSTS0 COMMENTS
Ted Musemwa
6986 POSTS0 COMMENTS
Thapelo Manthata
6661 POSTS0 COMMENTS
Umr Jansen
6679 POSTS0 COMMENTS