PHP 8.0.24 Released!


(PECL imagick 2, PECL imagick 3)

Imagick::getImageBlobRetourne la séquence d'images comme un blob


public Imagick::getImageBlob(): string

Implémente un formatage directe en mémoire. Il retourne la séquence d'images sous forme de chaîne. Le format de l'image détermine le format du BLOB retourné (GIF, JPEG, PNG, etc.). Pour retourner un format différent, utilisez la fonction Imagick::setImageFormat().

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Retourne une chaîne contenant les images.

Erreurs / Exceptions

Lance une exception ImagickException si une erreur survient.

add a note

User Contributed Notes 3 notes

Vee W
6 years ago
For who want to show "animated" gif. This getImageBlob() will showing only one frame of image.
Use getImagesBlob() instead.


= new \Imagick($real_source_image_path_animated_gif);
header("Content-Type: image/gif");
10 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.)
jim at jimohalloran dot com
1 year ago
Further to Trevor's note above about getImageBlob potentially returning an empty string for large images. 

This seems image format dependent.  I have a large (12046x8363) image which is returned ok.  But if I call setImageFormat('pdf') and then call getImageBlob() again.  Example:

// Image Manipulation here.
$pngData = $imagick->getImageBlob();  // Returns a large PNG.
$pdfData = $imagick->getImageBlob(); // Returns empty string immediately
To Top