-
Notifications
You must be signed in to change notification settings - Fork 19
/
crop.clj
30 lines (26 loc) · 906 Bytes
/
crop.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns image-resizer.crop
(:require
[image-resizer.util :refer :all])
(:import
[org.imgscalr Scalr]))
(defn- bound-dim [original-dim coord dim]
(if (> (+ coord dim) original-dim)
(- original-dim coord)
dim))
(defn crop-fn [x y width height]
(fn [image]
(let [buffered (buffered-image image)
[original-width original-height] (dimensions buffered)
crop-width (bound-dim original-width x width)
crop-height (bound-dim original-height y height)]
(Scalr/crop buffered x y crop-width crop-height nil))))
(defn crop-width-fn [width]
(fn [image]
(let [buffered (buffered-image image)
[_ height] (dimensions buffered)]
((crop-fn 0 0 width height) image))))
(defn crop-height-fn [height]
(fn [image]
(let [buffered (buffered-image image)
[width _] (dimensions buffered)]
((crop-fn 0 0 width height) image))))