2013-09-28 14:15:22 +02:00
|
|
|
(ns ldview.tasks.images
|
|
|
|
(:require [image-resizer.core :refer :all]
|
|
|
|
[image-resizer.util :as utils]
|
|
|
|
[image-resizer.format :refer :all]
|
|
|
|
[image-resizer.crop :refer :all]
|
2013-10-06 18:08:50 +02:00
|
|
|
[clojure.java.io :as io]
|
|
|
|
[noir.io :as noir-io]))
|
|
|
|
|
2014-04-24 23:26:24 +02:00
|
|
|
(defn base-path
|
|
|
|
([] (str (noir-io/resource-path) "img"))
|
|
|
|
([competition-id] (str (base-path) "/ld" competition-id "/")))
|
2013-09-28 14:15:22 +02:00
|
|
|
|
2014-01-31 00:02:26 +01:00
|
|
|
(defn image-name [competition-id folder entry-id number]
|
|
|
|
(str (base-path competition-id) folder "/" entry-id "_" number ".png"))
|
2013-09-28 14:15:22 +02:00
|
|
|
|
|
|
|
(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]
|
2013-09-30 00:37:38 +02:00
|
|
|
(with-redefs [image-resizer.fs/new-filename (fn [filepath dimensions] (str filepath))]
|
|
|
|
(as-file (to-square (io/file image-path) 200) new-image-path)))
|
2013-09-28 14:15:22 +02:00
|
|
|
|
|
|
|
(defn sourceimage->fullscreen [image-path new-image-path]
|
2013-09-30 00:37:38 +02:00
|
|
|
(with-redefs [image-resizer.fs/new-filename (fn [filepath dimensions] (str filepath))]
|
|
|
|
(as-file (resize (io/file image-path) 800 600) new-image-path)))
|
2013-09-28 14:15:22 +02:00
|
|
|
|