2

I convert animated gif to webp but the webp picture is not animated.

Did I miss a step? I don't find in the documentation.

my code:

//GD
$image = imagecreatefromgif("./mypics.gif");
imagepalettetotruecolor($image);
imagewebp($image, "./image.webp");

//Imagick
$img = new \Imagick("./mypics.gif");
$img->stripImage();
$img->setImageFormat("webp");
$img->setImageAlphaChannel(\imagick::ALPHACHANNEL_ACTIVATE);
$img->setBackgroundColor(new \ImagickPixel('transparent'));
$img->writeImage("./image.webp");
Ludovic
  • 501
  • 5
  • 10

2 Answers2

4

php-vips supports animated web. For example:

// n=-1 means load all pages
// sequential access means decode pixels on demand
$image = Vips\Image::newFromFile('something.gif', [
    'n' => -1,
    'access' => 'sequential'
]); 
$image->writeToFile('something.webp');
jcupitt
  • 10,213
  • 2
  • 23
  • 39
2

GD does not support animated WebP. Imagemagick does, but only since relatively recent version 7.0.8-68 and if compiled with libwebp.

You either need to install latest imagemagick with webp support, or use some other external tool, like gif2webp.

Maadinsh
  • 435
  • 5
  • 10
  • 1
    I installed imagemagick 7.0.10-24 and the webp are animated. For the moment I'm executing a command with the exec() function from PHP, because the php-imagick package uses a version that doesn't support animated webp. – Ludovic Jul 27 '20 at 05:48