forked from status-im/status-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_processing.cljs
More file actions
30 lines (26 loc) · 1.18 KB
/
image_processing.cljs
File metadata and controls
30 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns status-im.utils.image-processing
(:require [reagent.core :as r]
[status-im.utils.fs :refer [read-file]]
[taoensso.timbre :as log]
[clojure.string :as str]))
(def resizer-class (js/require "react-native-image-resizer"))
(defn- resize [path max-width max-height on-resize on-error]
(let [resize-fn (aget resizer-class "default" "createResizedImage")]
(-> (resize-fn path max-width max-height "JPEG" 75 0 nil)
(.then on-resize)
(.catch on-error))))
(defn- image-base64-encode [path on-success on-error]
(let [on-encoded (fn [data]
(on-success data))
on-error (fn [error]
(on-error :base64 error))]
(read-file path "base64" on-encoded on-error)))
(defn img->base64 [path on-success on-error]
(let [on-resized (fn [path]
(let [path (str/replace path "file:" "")]
(log/debug "Resized: " path)
(image-base64-encode path on-success on-error)))
on-error (fn [error]
(log/debug "Resized error: " error)
(on-error :resize error))]
(resize path 150 150 on-resized on-error)))