PHP 5.6.18 is available


(PECL imagick 2.0.0)

Imagick::getImageBlobReturns the image sequence as a blob


string Imagick::getImageBlob ( void )

Implements direct to memory image formats. It returns the image sequence as a string. The format of the image determines the format of the returned blob (GIF, JPEG, PNG, etc.). To return a different image format, use Imagick::setImageFormat().

Return Values

Returns a string containing the image.


Throws ImagickException on error.

add a note add a note

User Contributed Notes 1 note

4 years ago
It seems that this method can return a zero-length string if faced with large-ish data.  No exceptions are thrown.

= new Imagick();
  if (!
$image->newImage(1000,1,'white')) throw new Exception();
  if (!
$image->scaleImage(0,200)) throw new Exception();
"Image size: {$image->getImageWidth()},{$image->getImageHeight()}\n";
  if (!
$image->setImageFormat("jpeg")) throw new Exception();
$a = $image->getImageBlob();
"Rendered to ".strlen($a)." bytes\n";

Restrict your output image size, or ensure that the blob you get back isn't empty.  (Note that IM seems to be doing the work, it delays for some time.  But there's no indication of any error anywhere.)
To Top