From 9306c2a368cc7c7da577b6199440f4abc907af7d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 10 May 2019 15:32:29 +0200 Subject: [PATCH] Use Imagick to keep GIF animation 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 | 3 +++ src/Wallabag/CoreBundle/Helper/DownloadImages.php | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b28404e3..b1c144c7 100644 --- a/composer.json +++ b/composer.json @@ -103,6 +103,9 @@ "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", diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php index cc3dcfce..bc2afc64 100644 --- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php +++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php @@ -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': -- 2.41.0