Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/io/perun.clj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
(deftask images-resize
"Resize images to the provided resolutions.
Each image file would have resolution appended to it's name:
e.x. san-francisco.jpg would become san-francisco-3840.jpg"
e.x. san-francisco.jpg would become san-francisco_3840.jpg"
[o out-dir OUTDIR str "the output directory"
r resolutions RESOLUTIONS #{int} "resoulitions to which images should be resized"]
(boot/with-pre-wrap fileset
Expand All @@ -113,8 +113,9 @@
updated-files (pod/with-call-in @pod
(io.perun.contrib.images-resize/images-resize ~(.getPath tmp) ~files ~options))]
(perun/report-debug "images-resize" "new resized images" updated-files)
(pm/set-meta fileset updated-files)
(commit fileset tmp))))
(-> fileset
(commit tmp)
(pm/set-meta updated-files)))))

(def ^:private markdown-deps
'[[org.pegdown/pegdown "1.6.0"]
Expand Down Expand Up @@ -455,7 +456,7 @@

Returns a boot `with-pre-wrap` result"
[render-paths-fn options tracer]
(let [tmp (boot/tmp-dir!)]
(let [tmp (boot/tmp-dir!)]
(boot/with-pre-wrap fileset
(let [new-metadata (-> fileset
(render-paths-fn options)
Expand Down
29 changes: 12 additions & 17 deletions src/io/perun/contrib/images_resize.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
(perun/extension file-path)))

(defn ^String new-image-filepath [file-path filename new-filename]
(str (perun/parent-path file-path filename)
"/"
new-filename))
(perun/relativize-url
(str (perun/parent-path file-path filename)
"/"
new-filename)))

(defn write-file [options tmp file ^BufferedImage buffered-file resolution]
(let [filepath (:path file)
Expand All @@ -28,12 +29,11 @@
filepath-with-resolution (new-image-filepath filepath filename new-filename)
image-filepath (perun/create-filepath (:out-dir options) filepath-with-resolution)
new-file (io/file tmp image-filepath)]
(do
(io/make-parents new-file)
(ImageIO/write buffered-file (:extension file) new-file)
{:short-name (perun/filename new-filename)
:filename new-filename
:path image-filepath})))
(io/make-parents new-file)
(ImageIO/write buffered-file (:extension file) new-file)
{:short-name (perun/filename new-filename)
:filename new-filename
:path image-filepath}))

(defn resize-to [tgt-path file options resolution]
(let [io-file (-> file :full-path io/file)
Expand All @@ -42,18 +42,13 @@
new-dimensions (iu/dimensions resized-buffered-image)
new-meta (write-file options tgt-path file resized-buffered-image resolution)
dimensions {:width (first new-dimensions) :height (second new-dimensions)}]
(merge file new-meta dimensions)))
(merge file new-meta dimensions)))

(defn process-image [tgt-path file options]
(perun/report-debug "image-resize" "resizing" (:path file))
(let [resolutions (:resolutions options)]
(doall
(clojure.core/pmap
(fn [resolution]
(resize-to tgt-path file options resolution))
resolutions))))
(pmap #(resize-to tgt-path file options %) (:resolutions options)))

(defn images-resize [tgt-path files options]
(let [updated-files (flatten (doall (map #(process-image tgt-path % options) files)))]
(let [updated-files (doall (mapcat #(process-image tgt-path % options) files))]
(perun/report-info "image-resize" "processed %s image files" (count files))
updated-files))
2 changes: 1 addition & 1 deletion src/io/perun/gravatar.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns io.perun.gravatar
(:require [io.perun.core :as perun]
[gravatar :as gr]))
[gravatar.core :as gr]))

(defn add-gravatar [file source-prop target-prop]
(if-let [email (get file source-prop)]
Expand Down