Finish the image processing
This commit is contained in:
parent
c2d1dd3227
commit
5b2d7538ad
3 changed files with 86 additions and 78 deletions
22
project.clj
22
project.clj
|
@ -1,6 +1,6 @@
|
||||||
(defproject yenu "0.1.0-SNAPSHOT"
|
(defproject yenu "0.1.0-SNAPSHOT"
|
||||||
|
|
||||||
:description "FIXME: write description"
|
:description "yenu -- The image sharing tool for friends"
|
||||||
:url "http://example.com/FIXME"
|
:url "http://example.com/FIXME"
|
||||||
|
|
||||||
:dependencies [[bouncer "1.0.0"]
|
:dependencies [[bouncer "1.0.0"]
|
||||||
|
@ -30,7 +30,11 @@
|
||||||
[ring/ring-core "1.5.1"]
|
[ring/ring-core "1.5.1"]
|
||||||
[ring/ring-defaults "0.2.3"]
|
[ring/ring-defaults "0.2.3"]
|
||||||
[secretary "1.2.3"]
|
[secretary "1.2.3"]
|
||||||
[selmer "1.10.6"]]
|
[selmer "1.10.6"]
|
||||||
|
[image-resizer "0.1.9"]
|
||||||
|
[me.raynes/fs "1.4.6"]
|
||||||
|
[digest "1.4.5"]
|
||||||
|
[clj-exif-orientation "0.2.1"]]
|
||||||
|
|
||||||
:min-lein-version "2.0.0"
|
:min-lein-version "2.0.0"
|
||||||
|
|
||||||
|
@ -47,14 +51,14 @@
|
||||||
[lein-immutant "2.1.0"]
|
[lein-immutant "2.1.0"]
|
||||||
[lein-sassc "0.10.4"]
|
[lein-sassc "0.10.4"]
|
||||||
[lein-auto "0.1.2"]]
|
[lein-auto "0.1.2"]]
|
||||||
:sassc
|
:sassc
|
||||||
[{:src "resources/scss/screen.scss"
|
[{:src "resources/scss/screen.scss"
|
||||||
:output-to "resources/public/css/screen.css"
|
:output-to "resources/public/css/screen.css"
|
||||||
:style "nested"
|
:style "nested"
|
||||||
:import-path "resources/scss"}]
|
:import-path "resources/scss"}]
|
||||||
|
|
||||||
:auto
|
:auto
|
||||||
{"sassc" {:file-pattern #"\.(scss|sass)$" :paths ["resources/scss"]}}
|
{"sassc" {:file-pattern #"\.(scss|sass)$" :paths ["resources/scss"]}}
|
||||||
|
|
||||||
:hooks [leiningen.sassc]
|
:hooks [leiningen.sassc]
|
||||||
:clean-targets ^{:protect false}
|
:clean-targets ^{:protect false}
|
||||||
|
|
|
@ -1,69 +1,4 @@
|
||||||
html,
|
html, body {
|
||||||
body {
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||||
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
height: 100%;
|
||||||
height: 100%;
|
padding-top: 40px; }
|
||||||
}
|
|
||||||
.navbar {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
border-radius: 0px;
|
|
||||||
}
|
|
||||||
.navbar-brand {
|
|
||||||
float: none;
|
|
||||||
}
|
|
||||||
.navbar-nav .nav-item {
|
|
||||||
float: none;
|
|
||||||
}
|
|
||||||
.navbar-divider,
|
|
||||||
.navbar-nav .nav-item+.nav-item,
|
|
||||||
.navbar-nav .nav-link + .nav-link {
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
|
||||||
@media (min-width: 34em) {
|
|
||||||
.navbar-brand {
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
.navbar-nav .nav-item {
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
.navbar-divider,
|
|
||||||
.navbar-nav .nav-item+.nav-item,
|
|
||||||
.navbar-nav .nav-link + .nav-link {
|
|
||||||
margin-left: 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@-moz-keyframes three-quarters-loader {
|
|
||||||
0% {
|
|
||||||
-moz-transform: rotate(0deg);
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
-moz-transform: rotate(360deg);
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@-webkit-keyframes three-quarters-loader {
|
|
||||||
0% {
|
|
||||||
-webkit-transform: rotate(0deg);
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
-webkit-transform: rotate(360deg);
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@keyframes three-quarters-loader {
|
|
||||||
0% {
|
|
||||||
-moz-transform: rotate(0deg);
|
|
||||||
-ms-transform: rotate(0deg);
|
|
||||||
-webkit-transform: rotate(0deg);
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
-moz-transform: rotate(360deg);
|
|
||||||
-ms-transform: rotate(360deg);
|
|
||||||
-webkit-transform: rotate(360deg);
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
69
src/clj/yenu/helpers/images.clj
Normal file
69
src/clj/yenu/helpers/images.clj
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
(ns yenu.helpers.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]
|
||||||
|
[digest :as digest]
|
||||||
|
[me.raynes.fs :as fs]
|
||||||
|
[clj-exif-orientation.core :as exif]
|
||||||
|
[yenu.config :refer [env]]))
|
||||||
|
|
||||||
|
(defn create-needed-folders []
|
||||||
|
(if (not (fs/exists? (data-path "to-process")))
|
||||||
|
(fs/mkdirs (data-path "to-process")))
|
||||||
|
(if (not (fs/exists? (data-path "gallery")))
|
||||||
|
(map #(fs/mkdirs (data-path "gallery" %))
|
||||||
|
["normal" "raw" "thumbnails"])))
|
||||||
|
|
||||||
|
;;; HINT: To use the env function, the webserver need to be started with
|
||||||
|
;;; (start) in the 'user namespace.
|
||||||
|
(defn data-path
|
||||||
|
([] (data-path ""))
|
||||||
|
([& args]
|
||||||
|
(let [postfix (apply io/file args)]
|
||||||
|
(.getPath (io/file (env :user-dir) "data" postfix)))))
|
||||||
|
|
||||||
|
(defn target-image-filename [image-file-path]
|
||||||
|
(let [file (io/file image-file-path)]
|
||||||
|
(str (.lastModified file) "-" (digest/md5 file))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn scale-thumbnail [width]
|
||||||
|
#(let [image-file %
|
||||||
|
[orig-width orig-height] (dimensions (utils/buffered-image image-file))]
|
||||||
|
(if (< orig-width orig-height)
|
||||||
|
(let [resized-img (resize-to-width image-file width)
|
||||||
|
[w h] (dimensions resized-img)
|
||||||
|
crop-margin (quot (- h width) 2)]
|
||||||
|
(crop-from resized-img 0 crop-margin width width))
|
||||||
|
(let [resized-img (resize-to-height image-file width)
|
||||||
|
[w h] (dimensions resized-img)
|
||||||
|
crop-margin (quot (- w width) 2)]
|
||||||
|
(crop-from resized-img crop-margin 0 width width)))))
|
||||||
|
|
||||||
|
(defn scale-normal [width height]
|
||||||
|
#(resize % width height))
|
||||||
|
|
||||||
|
(defn save [fn params filepath target-filepath]
|
||||||
|
(let [file (exif/without-exif (io/file filepath))]
|
||||||
|
(as-file ((apply fn params) file)
|
||||||
|
target-filepath
|
||||||
|
:verbatim)))
|
||||||
|
|
||||||
|
(defn scale-image-and-save [filepath]
|
||||||
|
(let [image-hash (target-image-filename filepath)
|
||||||
|
file-extension (fs/extension filepath)
|
||||||
|
new-file-name (str image-hash file-extension)]
|
||||||
|
(fs/copy filepath (data-path "gallery" "raw" new-file-name))
|
||||||
|
(save scale-normal [1024 768] filepath (data-path "gallery" "normal" new-file-name))
|
||||||
|
(save scale-thumbnail [250] filepath (data-path "gallery" "thumbnails" new-file-name))
|
||||||
|
image-hash))
|
||||||
|
|
||||||
|
(defn process-image [filepath]
|
||||||
|
(let [image-hash (scale-image-and-save filepath)]
|
||||||
|
(fs/delete filepath)
|
||||||
|
image-hash))
|
||||||
|
|
||||||
|
(defn process-all-images []
|
||||||
|
(pmap process-image (fs/list-dir (data-path "to-process"))))
|
Loading…
Reference in a new issue