From 921d00a6ab342963f419a2043e30d8457ffd3ac2 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 2 Apr 2014 22:17:45 -0400 Subject: [PATCH] convert frame delays to milliseconds and fix really low delays --- src/clojure/clj_image2ascii/core.clj | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/clojure/clj_image2ascii/core.clj b/src/clojure/clj_image2ascii/core.clj index 0f021a7..d61e39b 100644 --- a/src/clojure/clj_image2ascii/core.clj +++ b/src/clojure/clj_image2ascii/core.clj @@ -75,13 +75,23 @@ :color? (if color? true false) ; forcing an explicit true/false because i am nitpicky like that :image (ImageToAscii/convert final-image color?)}))) +(defn- fix-gif-frame-delay [delay] + ; based on the findings here: http://nullsleep.tumblr.com/post/16524517190/animated-gif-minimum-frame-delay-browser-compatibility + ; basically, we should not allow any delay less then 0.02s (20ms) because none of the major browsers support it + ; and this library is primarily intended for web use, where we want to mimic GIF-like playback (even though we + ; won't be held by the same limitations since we will be using javascript for our animation) + (let [ms (* delay 10)] + (if (< ms 20) + 20 + ms))) + (defn- get-ascii-gif-frames [^ImageInputStream image-stream scale-to-width color?] (->> (AnimatedGif/read image-stream) (mapv (fn [^ImageFrame frame] (-> (.image frame) (convert-image scale-to-width color?) - (assoc :delay (.delay frame))))))) + (assoc :delay (fix-gif-frame-delay (.delay frame)))))))) (defn convert-animated-gif-frames ([^ImageInputStream image-stream color?]