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 hook.image | |
(:use clojure.java.io) | |
(:import org.apache.sanselan.Sanselan | |
org.apache.sanselan.ImageFormat | |
java.awt.geom.AffineTransform | |
java.awt.image.AffineTransformOp)) | |
(defn subimage | |
"Returns a subimage of the provided image." | |
([img {x :x y :y w :width h :height}] (subimage img x y w h)) | |
([img x y w] (subimage img x y w w)) | |
([img x y w h] (.getSubimage img x y w h))) | |
(defn translate | |
"Returns a translated version of the provided image." | |
[img x y] | |
(let [t (AffineTransform.)] | |
(.translate t x y) | |
(.filter (AffineTransformOp. t (AffineTransformOp/TYPE_BILINEAR)) img nil))) | |
(defn rotate | |
"Returns a rotated version of the provided image." | |
([img a] (rotate img a 0 0)) | |
([img a x y] | |
(let [t (AffineTransform.)] | |
(.rotate t a x y) | |
(.filter (AffineTransformOp. t (AffineTransformOp/TYPE_BILINEAR)) img nil)))) | |
(defn load [pth] | |
(Sanselan/getBufferedImage (file pth))) | |
(defn store | |
([img pth] (store img pth :tiff)) | |
([img pth typ] | |
(let [typ-enum (case typ | |
:tiff ImageFormat/IMAGE_FORMAT_TIFF | |
:png ImageFormat/IMAGE_FORMAT_PNG | |
:jbig2 ImageFormat/IMAGE_FORMAT_JBIG2)] | |
(Sanselan/writeImage img (file pth) typ-enum nil)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment