From 9306c2a368cc7c7da577b6199440f4abc907af7d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 10 May 2019 15:32:29 +0200 Subject: 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. --- src/Wallabag/CoreBundle/Helper/DownloadImages.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle') 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': -- cgit v1.2.3 From 844fd9fafc577faa8d6c8faa4e37b915be2389d9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 10 May 2019 16:52:01 +0200 Subject: Fallback to default solution if Imagick fails --- src/Wallabag/CoreBundle/Helper/DownloadImages.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/CoreBundle') diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php index bc2afc64..9a7e9828 100644 --- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php +++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php @@ -137,10 +137,15 @@ class DownloadImages case 'gif': // 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); + try { + $imagick = new \Imagick(); + $imagick->readImageBlob($res->getBody()); + $imagick->setImageFormat('gif'); + $imagick->writeImages($localPath, true); + } catch (\Exception $e) { + // if Imagick fail, fallback to the default solution + imagegif($im, $localPath); + } } else { imagegif($im, $localPath); } -- cgit v1.2.3