Imagick::getImageBlob

(PECL imagick 2, PECL imagick 3)

Imagick::getImageBlob β€” Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ Π² Π²ΠΈΠ΄Π΅ BLOB

ОписаниС

public function Imagick::getImageBlob(): string

Π Π΅Π°Π»ΠΈΠ·ΡƒΠ΅Ρ‚ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Ρ‹ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ Π² ΠΏΠ°ΠΌΡΡ‚ΡŒ. Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ Π² Π²ΠΈΠ΄Π΅ строки. Π€ΠΎΡ€ΠΌΠ°Ρ‚ изобраТСния опрСдСляСт Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΠΎΠ³ΠΎ BLOB-ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° (GIF, JPEG, PNG ΠΈ Ρ‚.Π΄.). Π§Ρ‚ΠΎΠ±Ρ‹ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ Π΄Ρ€ΡƒΠ³ΠΎΠΉ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ изобраТСния, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Imagick::setImageFormat().

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

Π‘ΠΈΠ³Π½Π°Ρ‚ΡƒΡ€Π° Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π½Π΅ содСрТит ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ².

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ строку, ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‰ΡƒΡŽ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅.

Ошибки

Ѐункция выбрасываСт ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ImagickException, Ссли Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ошибка.

οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 4 notes

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

Example:

<?php
$Imagick = new \Imagick($real_source_image_path_animated_gif);
header("Content-Type: image/gif");
echo $Imagick->getImagesBlob();
?>
up
2
anonymous at internet dot domain ΒΆ
2 years ago
Function returns NULL without any error if ImageMagick policy.xml blocks handling the file format, i.e. PDF.
For PDF output edit /etc/ImageMagick-6/policy.xml and remove the line which disables rights for PDF.
If you use other functions, e.g. readImage() for PDF, ImageMagick nags about it and outputs the error message but this function fails silently.
up
0
Trevor ΒΆ
14 years ago
It seems that this method can return a zero-length string if faced with large-ish data.  No exceptions are thrown.

<?php
  $image = new Imagick();
  if (!$image->newImage(1000,1,'white')) throw new Exception();
  if (!$image->scaleImage(0,200)) throw new Exception();
  print "Image size: {$image->getImageWidth()},{$image->getImageHeight()}\n";
  if (!$image->setImageFormat("jpeg")) throw new Exception();
  $a = $image->getImageBlob();
  print "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.)
up
-1
jim at jimohalloran dot com ΒΆ
4 years 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:

<?php
// Image Manipulation here.
$pngData = $imagick->getImageBlob();  // Returns a large PNG.
$imagick->setImageFormat('pdf');
$pdfData = $imagick->getImageBlob(); // Returns empty string immediately
?>