Handy Resize functions
This commit is contained in:
parent
9809403e19
commit
dce6a86ec7
1 changed files with 34 additions and 0 deletions
34
src/luduverse/ld-images.clj
Normal file
34
src/luduverse/ld-images.clj
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
(ns luduverse.ld-images
|
||||||
|
(:require [image-resizer.core :refer :all]
|
||||||
|
[image-resizer.util :as utils]
|
||||||
|
[image-resizer.format :refer :all]
|
||||||
|
[image-resizer.crop :refer :all]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[noir.io :as noir-io]))
|
||||||
|
|
||||||
|
(defn base-path
|
||||||
|
([] (str (noir-io/resource-path) "img"))
|
||||||
|
([competition-id] (str (base-path) "/ld" competition-id "/")))
|
||||||
|
|
||||||
|
(defn image-name [competition-id folder entry-id number]
|
||||||
|
(str (base-path competition-id) folder "/" entry-id "_" number ".png"))
|
||||||
|
|
||||||
|
(defn to-square [file new-size]
|
||||||
|
(let [[width height] (dimensions (utils/buffered-image file))]
|
||||||
|
(if (< width height)
|
||||||
|
(let [resized-img (resize-to-width file new-size)
|
||||||
|
[w h] (dimensions resized-img)
|
||||||
|
crop-margin (quot (- h new-size) 2)]
|
||||||
|
(crop-from resized-img 0 crop-margin new-size new-size))
|
||||||
|
(let [resized-img (resize-to-height file new-size)
|
||||||
|
[w h] (dimensions resized-img)
|
||||||
|
crop-margin (quot (- w new-size) 2)]
|
||||||
|
(crop-from resized-img crop-margin 0 new-size new-size)))))
|
||||||
|
|
||||||
|
(defn sourceimage->thumb [image-path new-image-path]
|
||||||
|
(with-redefs [image-resizer.fs/new-filename (fn [filepath dimensions] (str filepath))]
|
||||||
|
(as-file (to-square (io/file image-path) 200) new-image-path)))
|
||||||
|
|
||||||
|
(defn sourceimage->fullscreen [image-path new-image-path]
|
||||||
|
(with-redefs [image-resizer.fs/new-filename (fn [filepath dimensions] (str filepath))]
|
||||||
|
(as-file (resize (io/file image-path) 800 600) new-image-path)))
|
Loading…
Reference in a new issue