little bit of cleanup
This commit is contained in:
parent
1732ccf341
commit
59a829b9ef
|
@ -1,13 +1,11 @@
|
|||
(ns toascii.models.image
|
||||
(:import (java.awt.image BufferedImage)
|
||||
(java.io Writer)
|
||||
(javax.imageio.stream ImageInputStream))
|
||||
(:require [clojure.string :as str]
|
||||
[clojure.java.io :as io]
|
||||
(javax.imageio.stream ImageInputStream)
|
||||
(java.io Writer))
|
||||
(:require [clojure.java.io :as io]
|
||||
[ring.util.io :refer [piped-input-stream]]
|
||||
[clj-image2ascii.core :as i2a]
|
||||
[toascii.util :refer [query-param-url->java-url]])
|
||||
(:use hiccup.core))
|
||||
[toascii.util :refer [query-param-url->java-url]]))
|
||||
|
||||
(def js-gif-animation (slurp (io/resource "gif-animation.js")))
|
||||
|
||||
|
@ -21,33 +19,11 @@
|
|||
(let [java-url (query-param-url->java-url url)]
|
||||
(i2a/get-image-stream-by-url java-url)))
|
||||
|
||||
(defn- wrap-pre-tag [s & {:keys [hidden? delay]}]
|
||||
(str
|
||||
"<pre style=\""
|
||||
ascii-pre-css
|
||||
(if hidden?
|
||||
" display: none;")
|
||||
"\""
|
||||
(if delay
|
||||
(str " data-delay=\"" delay "\""))
|
||||
">" s "</pre>"))
|
||||
|
||||
(defn- get-open-pre-tag [hidden? delay]
|
||||
(str
|
||||
"<pre style=\""
|
||||
ascii-pre-css
|
||||
(if hidden?
|
||||
" display: none;")
|
||||
"\""
|
||||
(if delay
|
||||
(str " data-delay=\"" delay "\""))
|
||||
">"))
|
||||
|
||||
(defn image->ascii [^BufferedImage image scale-to-width color? html?]
|
||||
(let [converted (i2a/convert-image image scale-to-width color?)
|
||||
ascii (:image converted)]
|
||||
(if html?
|
||||
(wrap-pre-tag ascii)
|
||||
(str "<pre style=\"" ascii-pre-css "\">" ascii "</pre>")
|
||||
ascii)))
|
||||
|
||||
(defn- write-out [^Writer w s]
|
||||
|
@ -61,9 +37,9 @@
|
|||
(i2a/stream-animated-gif-frames!
|
||||
image-stream scale-to-width color?
|
||||
(fn [{:keys [image delay]}]
|
||||
(write-out w (get-open-pre-tag true delay))
|
||||
(write-out w image)
|
||||
(write-out w "</pre>")))
|
||||
(write-out w (str "<pre style=\"" ascii-pre-css " display: none;\" data-delay=\"" delay "\">"))
|
||||
(write-out w image)
|
||||
(write-out w "</pre>")))
|
||||
(write-out w "</div>")
|
||||
(write-out w "<script type=\"text/javascript\">")
|
||||
(write-out w js-gif-animation)
|
||||
|
|
Reference in a new issue