         r (bit-and (bit-shift-right pixel 16) 0x000000FF)
         g (bit-and (bit-shift-right pixel 8) 0x000000FF)
         b (bit-and pixel 0x000000FF)
-        max-color (max r g b)
+        max-color (int (Math/sqrt (+ (* r r 0.241) (* g g 0.691) (* b b 0.068))))
         idx (if (zero? max-color) max-items (int (* max-items (/ max-color 255))))]
     (nth ascii (max idx 0))))
 

                    :style "font-size:5pt;line-height:5pt;letter-spacing:1px;font-weight:bold;display:none;font-family:monospace;"}
                   (to-ascii (scale-image (.read ^ImageReader rdr i) w h))])
               (range frame-count))])
       :frames frame-count})))

(defn scale [a b]
  (int (* (/ 100 a) b)))

(defn delay [rdr]
  (try
    (let [image-meta  (.getImageMetadata rdr 0)
          format-name (.getNativeMetadataFormatName image-meta)
          root        (.getAsTree image-meta format-name)]
      (as-> (range (.getLength root)) x
            (map #(.item root %) x)
            (filter #(= 0 (.compareToIgnoreCase (.getNodeName %) "GraphicControlExtension")) x)
            (first x)
            (.getAttribute x "delayTime")
            (Integer/parseInt x)))
    (catch Exception _ 0)))

(defn gif->html [input]
  (let [rdr  ^ ImageReader (.next (ImageIO/getImageReadersByFormatName "gif"))
        ciis (ImageIO/createImageInputStream input)]
    (.setInput rdr ciis false)    
    (let [frame-count (.getNumImages rdr true)
          frame-delay (delay rdr)
          w           (.getWidth rdr 0)
          h           (.getHeight rdr 0)
          [w h]       (cond
