mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 23:06:10 +02:00
✨ Upload SVG as shapes
This commit is contained in:
parent
5b79928590
commit
802f19453d
28 changed files with 839 additions and 244 deletions
|
@ -11,6 +11,7 @@
|
|||
(:require
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.spec :as us]
|
||||
[cuerdas.core :as str]
|
||||
[app.metrics :as mtx]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.java.shell :as shell]
|
||||
|
@ -25,10 +26,25 @@
|
|||
[^String data]
|
||||
(IOUtils/toInputStream data "UTF-8"))
|
||||
|
||||
(defn- stream->string
|
||||
[input]
|
||||
(with-open [istream (io/input-stream input)]
|
||||
(-> (IOUtils/toString input "UTF-8"))))
|
||||
|
||||
(defn- clean-svg
|
||||
[^InputStream input]
|
||||
(let [result (shell/sh "svgcleaner" "-c" "-" :in input :out-enc :bytes)]
|
||||
(when (not= 0 (:exit result))
|
||||
(let [result (shell/sh
|
||||
;; "svgcleaner" "--allow-bigger-file" "-c" "-"
|
||||
"svgo"
|
||||
"--enable=prefixIds,removeDimensions,removeXMLNS,removeScriptElement"
|
||||
"--disable=removeViewBox,moveElemsAttrsToGroup"
|
||||
"-i" "-" "-o" "-"
|
||||
|
||||
:in input :out-enc :bytes)
|
||||
err-str (:err result)]
|
||||
(when (or (not= 0 (:exit result))
|
||||
;; svgcleaner returns 0 with some errors, we need to check
|
||||
(and (not= err-str "") (not (nil? err-str)) (str/starts-with? err-str "Error")))
|
||||
(ex/raise :type :validation
|
||||
:code :unable-to-optimize
|
||||
:hint (:err result)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue