Created
March 10, 2013 17:39
-
-
Save philopon/5129592 to your computer and use it in GitHub Desktop.
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
(ns excel-oekaki.core | |
(:import | |
(java.io File FileOutputStream FileInputStream) | |
(java.awt Color) | |
(javax.imageio ImageIO) | |
(org.apache.poi.xssf.usermodel XSSFWorkbook XSSFColor) | |
(org.apache.poi.ss.usermodel CellStyle) | |
)) | |
(defn -main [iname oname] | |
(with-open [out (FileOutputStream. oname)] | |
(let [image (ImageIO/read (File. iname)) | |
wb (XSSFWorkbook.) | |
sheet (.createSheet wb "oekaki") | |
dict (atom (array-map))] | |
(dorun | |
(for [y (range (.getMinY image) (.getHeight image))] | |
(let [row (.createRow sheet y)] | |
(println y (count @dict)) | |
(dorun | |
(for [x (range (.getMinX image) (.getWidth image))] | |
(let [cell (.createCell row x) | |
rgb (.getRGB image x y) | |
inDict (find @dict rgb)] | |
(if inDict | |
(.setCellStyle cell (last inDict)) | |
(let [style (.createCellStyle wb) | |
color (XSSFColor. (Color. (.getRGB image x y)))] | |
(.setFillForegroundColor style color) | |
(.setFillPattern style CellStyle/SOLID_FOREGROUND) | |
(.setCellStyle cell style) | |
(swap! dict assoc rgb style))))))))) | |
(.write wb out)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment