Created
November 9, 2010 05:20
-
-
Save joubertnel/668737 to your computer and use it in GitHub Desktop.
Create thumbnail of image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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