Skip to content

Instantly share code, notes, and snippets.

@PaulSandoz
Created November 2, 2011 19:54
Show Gist options
  • Save PaulSandoz/1334699 to your computer and use it in GitHub Desktop.
Save PaulSandoz/1334699 to your computer and use it in GitHub Desktop.
(defn render-image [image]
(let [out (ByteArrayOutputStream.)]
(do (ImageIO/write image "png" out) (ByteArrayInputStream. (.toByteArray out)))))
; ":use" needed for compojure.response
(extend-protocol Renderable
BufferedImage
(render [image _]
(-> (ring.util.response/response (render-image image))
(ring.util.response/content-type "image/png"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment