Skip to content

Instantly share code, notes, and snippets.

@joubertnel
Created November 9, 2010 05:20
Show Gist options
  • Save joubertnel/668737 to your computer and use it in GitHub Desktop.
Save joubertnel/668737 to your computer and use it in GitHub Desktop.
Create thumbnail of image
(defn make-thumbnail [in-stream out-stream width]
(let [img (javax.imageio.ImageIO/read in-stream)
imgtype (java.awt.image.BufferedImage/TYPE_INT_ARGB)
width (min (.getWidth img) width)
height (* (/ width (.getWidth img)) (.getHeight img))
simg (java.awt.image.BufferedImage. width height imgtype)
g (.createGraphics simg)]
(.drawImage g img 0 0 width height nil)
(.dispose g)
(javax.imageio.ImageIO/write simg "png" out-stream)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment