diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-05-10 15:32:29 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-05-10 15:33:36 +0200 |
commit | 9306c2a368cc7c7da577b6199440f4abc907af7d (patch) | |
tree | e511f3bed1d6416f311dd1bab647a774c3342cfc | |
parent | 6e67f41152ad025e74696e7140de0f9fb0d601de (diff) | |
download | wallabag-9306c2a368cc7c7da577b6199440f4abc907af7d.tar.gz wallabag-9306c2a368cc7c7da577b6199440f4abc907af7d.tar.zst wallabag-9306c2a368cc7c7da577b6199440f4abc907af7d.zip |
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.
-rw-r--r-- | composer.json | 3 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/DownloadImages.php | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/composer.json b/composer.json index b28404e3..b1c144c7 100644 --- a/composer.json +++ b/composer.json | |||
@@ -103,6 +103,9 @@ | |||
103 | "phpstan/phpstan-symfony": "^0.11.0", | 103 | "phpstan/phpstan-symfony": "^0.11.0", |
104 | "phpstan/phpstan-doctrine": "^0.11.0" | 104 | "phpstan/phpstan-doctrine": "^0.11.0" |
105 | }, | 105 | }, |
106 | "suggest": { | ||
107 | "ext-imagick": "To keep GIF animation when downloading image is enabled" | ||
108 | }, | ||
106 | "scripts": { | 109 | "scripts": { |
107 | "post-cmd": [ | 110 | "post-cmd": [ |
108 | "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", | 111 | "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 | |||
135 | 135 | ||
136 | switch ($ext) { | 136 | switch ($ext) { |
137 | case 'gif': | 137 | case 'gif': |
138 | imagegif($im, $localPath); | 138 | // use Imagick if available to keep GIF animation |
139 | if (class_exists('\\Imagick')) { | ||
140 | $imagick = new \Imagick(); | ||
141 | $imagick->readImageBlob($res->getBody()); | ||
142 | $imagick->setImageFormat('gif'); | ||
143 | $imagick->writeImages($localPath, true); | ||
144 | } else { | ||
145 | imagegif($im, $localPath); | ||
146 | } | ||
147 | |||
139 | $this->logger->debug('DownloadImages: Re-creating gif'); | 148 | $this->logger->debug('DownloadImages: Re-creating gif'); |
140 | break; | 149 | break; |
141 | case 'jpeg': | 150 | case 'jpeg': |