]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Use Imagick to keep GIF animation
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 10 May 2019 13:32:29 +0000 (15:32 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 10 May 2019 13:33:36 +0000 (15:33 +0200)
If Imagick is available, GIF will be saved using it to keep animation.
Otherwise the previous method will be used and the animation won't be kept.

composer.json
src/Wallabag/CoreBundle/Helper/DownloadImages.php

index b28404e3c8efd19f0c25073c85f6f720fce28237..b1c144c72356d1c1c957f8ff578df4e1d99a877f 100644 (file)
         "phpstan/phpstan-symfony": "^0.11.0",
         "phpstan/phpstan-doctrine": "^0.11.0"
     },
+    "suggest": {
+        "ext-imagick": "To keep GIF animation when downloading image is enabled"
+    },
     "scripts": {
         "post-cmd": [
             "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
index cc3dcfceb7796ffcb457e749eb654680347f3dc8..bc2afc646cb79819ac05a9574ef96fe68afa7ba7 100644 (file)
@@ -135,7 +135,16 @@ class DownloadImages
 
         switch ($ext) {
             case 'gif':
-                imagegif($im, $localPath);
+                // use Imagick if available to keep GIF animation
+                if (class_exists('\\Imagick')) {
+                    $imagick = new \Imagick();
+                    $imagick->readImageBlob($res->getBody());
+                    $imagick->setImageFormat('gif');
+                    $imagick->writeImages($localPath, true);
+                } else {
+                    imagegif($im, $localPath);
+                }
+
                 $this->logger->debug('DownloadImages: Re-creating gif');
                 break;
             case 'jpeg':