Last active
July 20, 2017 09:50
-
-
Save minikomi/cf52abb63d2f8dddd1ebd24de4045261 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 write-image! | |
([ext buffered-image output-file] | |
(write-image! ext buffered-image output-file {:quality 1.0})) | |
([ext buffered-image output-file options] | |
(let [writer (.next (ImageIO/getImageWritersByFormatName ext)) | |
write-param (.getDefaultWriteParam writer) | |
iioimage (IIOImage. buffered-image nil nil) | |
ios (ImageIO/createImageOutputStream output-file)] | |
(doto write-param | |
(.setCompressionMode ImageWriteParam/MODE_EXPLICIT) | |
(.setCompressionQuality (:quality options))) | |
(doto writer | |
(.setOutput ios) | |
(.write nil iioimage write-param) | |
(.dispose)) | |
(doto ios | |
(.close))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment