summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-04-29 15:22:54 +0300
committerAndrew Dolgov <[email protected]>2020-04-29 15:22:54 +0300
commit070d17c8dd14a61c7dd5c2ec6b6aff6d9a4c5bd1 (patch)
tree43c98aa6f8b90a6dee8104e3c0cf532a81cf3870
parent8e0d742cc4fbc7d79b27a3323e7836f560a6d440 (diff)
put media stamps on animated gifs
-rw-r--r--init.php35
1 files changed, 34 insertions, 1 deletions
diff --git a/init.php b/init.php
index cb97ecb..056ec85 100644
--- a/init.php
+++ b/init.php
@@ -60,7 +60,9 @@ class Api_Resize_Media extends Plugin {
$t_im = imageCreateTrueColor($t_width, $t_height);
$need_stamp = false;
- if ($force_stamp /*|| ($enable_stamp && $imageinfo && $imageinfo["mime"] == "image/gif")*/) {
+ if ($force_stamp || ($imageinfo && $imageinfo["mime"] == "image/gif" &&
+ $this->is_animated_gif($input_filename))) {
+
$need_stamp = true;
imageFill($t_im, 0, 0, 0xffffff);
/*} else { -- this might make resized image significantly larger
@@ -297,6 +299,37 @@ class Api_Resize_Media extends Plugin {
return $article;
}
+ // https://stackoverflow.com/questions/280658/can-i-detect-animated-gifs-using-php-and-gd
+ function is_animated_gif ($filename) {
+ $raw = file_get_contents($filename);
+
+ if ($raw) {
+ $offset = 0;
+ $frames = 0;
+ while ($frames < 2 && $offset <= 500000) {
+ $where1 = strpos($raw, "\x00\x21\xF9\x04", $offset);
+
+ if ($where1 === false) {
+ break;
+ } else {
+ $offset = $where1 + 1;
+ $where2 = strpos($raw, "\x00\x2C", $offset);
+ if ($where2 === false) {
+ break;
+ } else {
+ if ($where1 + 8 == $where2) {
+ $frames++;
+ }
+ $offset = $where2 + 1;
+ }
+ }
+ }
+ return $frames > 1;
+ }
+
+ return false;
+ }
+
function api_version() {
return 2;
}