0

I am using PHP libvips library when I am using this function writeToBuffer for write to buffer the image it gives me below types of error.

Fatal error: Uncaught Jcupitt\Vips\Exception: magicksave_buffer: libMagick error: no decode delegate for this image format `' @ error/blob.c/ImagesToBlob/2413

Note - This error occurs only when my image type is gif

$imagePathInfo = pathinfo($inputFileName);
$imgExtension = $imagePathInfo['extension'];
$img = Vips\Image::newFromFile($inputFileName, ['access' => 'sequential']);
$img = $img->writeToBuffer('.' . $imgExtension);

Image which I am trying

Vinay Kapoor
  • 47
  • 1
  • 10

1 Answers1

0

By default libvips will only load the first frame of an animation. To load all frames, set the n parameter (number of pages) to -1. Use:

$img = Vips\Image::newFromFile($inputFileName, [
    'access' => 'sequential', 
    'n' => -1
]);

libvips 8.11 uses imagemagick to write GIF images. You need to tell imagemagick what format to write in with the format parameter, eg.:

$img = $img->writeToBuffer('.' . $imgExtension, [
    'format' => $imgExtension
]);

libvips 8.12 (due by the end of Nov 2021) will automatically pass the correct format value to imagemagick, and also has a dedicated and much faster GIF writer.

jcupitt
  • 10,213
  • 2
  • 23
  • 39
  • If I pass image extension, does it works for all images like I have on common function in my class, which accepts the file name (with jpg, jpeg extension etc..). My question is Is the last solution which you gave will work for all types of images? – Vinay Kapoor Nov 15 '21 at 10:54
  • No, you'll need to handle GIFs as a separate case for now. libvips 8.12 fixes this. – jcupitt Nov 15 '21 at 12:59