🐛 Fixed problem with import SVG image size

This commit is contained in:
alonso.torres 2020-12-07 14:55:09 +01:00 committed by Alonso Torres
parent 4ef471919c
commit b80332b9b3
2 changed files with 15 additions and 14 deletions

View file

@ -119,20 +119,20 @@
[{:keys [input] :as params}] [{:keys [input] :as params}]
(us/assert ::input input) (us/assert ::input input)
(let [{:keys [path mtype]} input] (let [{:keys [path mtype]} input]
(if (= mtype "image/svg+xml") (let [instance (Info. (str path))
{:width 100
:height 100 ;; SVG files are converted to PNG to extract their properties
:mtype mtype} mtype (if (= mtype "image/svg+xml") "image/png" mtype)
(let [instance (Info. (str path)) mtype' (.getProperty instance "Mime type")]
mtype' (.getProperty instance "Mime type")] (when (and (string? mtype)
(when (and (string? mtype) (not= mtype mtype'))
(not= mtype mtype')) (ex/raise :type :validation
(ex/raise :type :validation :code :media-type-mismatch
:code :media-type-mismatch :hint (str "Seems like you are uploading a file whose content does not match the extension."
:hint "Seems like you are uploading a file whose content does not match the extension.")) "Expected: " mtype "Got: " mtype')))
{:width (.getImageWidth instance) {:width (.getImageWidth instance)
:height (.getImageHeight instance) :height (.getImageHeight instance)
:mtype mtype'})))) :mtype mtype'})))
(defmethod process :default (defmethod process :default
[{:keys [cmd] :as params}] [{:keys [cmd] :as params}]

View file

@ -41,6 +41,7 @@ RUN set -ex; \
python \ python \
build-essential \ build-essential \
imagemagick \ imagemagick \
librsvg2-bin \
netpbm \ netpbm \
potrace \ potrace \
webp \ webp \