mirror of https://github.com/penpot/penpot.git
🐛 Add method to retrieve image data in plugins
This commit is contained in:
parent
4a887840c6
commit
4cdf1eed0c
|
|
@ -8,6 +8,7 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.plugins.image-data :refer [create-image-data]]
|
||||
[app.util.object :as obj]))
|
||||
|
||||
(def shape-proxy nil)
|
||||
|
|
@ -106,15 +107,9 @@
|
|||
;; keepAspectRatio?: boolean;
|
||||
;; };
|
||||
(defn format-image
|
||||
[{:keys [name width height mtype id keep-aspect-ratio] :as image}]
|
||||
[image]
|
||||
(when (some? image)
|
||||
(obj/without-empty
|
||||
#js {:name name
|
||||
:width width
|
||||
:height height
|
||||
:mtype mtype
|
||||
:id (format-id id)
|
||||
:keepAspectRatio keep-aspect-ratio})))
|
||||
(create-image-data image)))
|
||||
|
||||
;; export interface Color {
|
||||
;; id?: string;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.plugins.image-data
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.config :as cf]
|
||||
[app.util.http :as http]
|
||||
[app.util.object :as obj]
|
||||
[beicon.v2.core :as rx]))
|
||||
|
||||
(defn create-image-data
|
||||
[{:keys [name width height mtype id keep-aspect-ratio] :as entry}]
|
||||
(obj/reify {:name "ImageData"}
|
||||
:name {:get (constantly name)}
|
||||
:width {:get (constantly width)}
|
||||
:height {:get (constantly height)}
|
||||
:mtype {:get (constantly mtype)}
|
||||
:id {:get #(when id (dm/str id))}
|
||||
:keepAspectRatio {:get (constantly keep-aspect-ratio)}
|
||||
|
||||
:data
|
||||
(fn []
|
||||
(let [url (cf/resolve-file-media entry)]
|
||||
(js/Promise.
|
||||
(fn [resolve reject]
|
||||
(->> (http/send!
|
||||
{:method :get
|
||||
:uri url
|
||||
:response-type :blob})
|
||||
(rx/map :body)
|
||||
(rx/mapcat #(.arrayBuffer %))
|
||||
(rx/map #(js/Uint8Array. %))
|
||||
(rx/subs! resolve reject))))))))
|
||||
Loading…
Reference in New Issue