简体   繁体   中英

How to resize an animated gif with ImageMagick (php)?

I cannot find a working example. This one is not working, it's not animated:

$imagick = new Imagick($_FILES['file']['tmp_name']);

$format = $imagick->getImageFormat();
if ($format == 'GIF') {
  $imagick = $imagick->coalesceImages();
  do {
     $imagick->resizeImage(500, 500, Imagick::FILTER_BOX, 1);
  } while ($imagick->nextImage());
  $imagick = $imagick->deconstructImages();
  $imagick->writeImages($name, true);

}

$imagick->clear();
$imagick->destroy();

In ImageMagick command line, this works for me

Original Animation:

在此处输入图片说明

convert animation.gif -coalesce -resize 500x500 -layers optimize -loop 0 resize.gif

在此处输入图片说明

Did you do the equivalent of -coalesce after reading your input animation? Did you do the optimize step after resizing?

Sorry, I do not use PHP Imagick or any other API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM