(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] [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)))