From b80332b9b34ca67012f6b5efc171d819ab48b5e0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 7 Dec 2020 14:55:09 +0100 Subject: [PATCH] :bug: Fixed problem with import SVG image size --- backend/src/app/media.clj | 28 ++++++++++++++-------------- docker/devenv/Dockerfile | 1 + 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 51b7186d3..a05f4c0c4 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -119,20 +119,20 @@ [{:keys [input] :as params}] (us/assert ::input input) (let [{:keys [path mtype]} input] - (if (= mtype "image/svg+xml") - {:width 100 - :height 100 - :mtype mtype} - (let [instance (Info. (str path)) - mtype' (.getProperty instance "Mime type")] - (when (and (string? mtype) - (not= mtype mtype')) - (ex/raise :type :validation - :code :media-type-mismatch - :hint "Seems like you are uploading a file whose content does not match the extension.")) - {:width (.getImageWidth instance) - :height (.getImageHeight instance) - :mtype mtype'})))) + (let [instance (Info. (str path)) + + ;; SVG files are converted to PNG to extract their properties + mtype (if (= mtype "image/svg+xml") "image/png" mtype) + mtype' (.getProperty instance "Mime type")] + (when (and (string? mtype) + (not= mtype mtype')) + (ex/raise :type :validation + :code :media-type-mismatch + :hint (str "Seems like you are uploading a file whose content does not match the extension." + "Expected: " mtype "Got: " mtype'))) + {:width (.getImageWidth instance) + :height (.getImageHeight instance) + :mtype mtype'}))) (defmethod process :default [{:keys [cmd] :as params}] diff --git a/docker/devenv/Dockerfile b/docker/devenv/Dockerfile index 6d345686d..e8b51a18e 100644 --- a/docker/devenv/Dockerfile +++ b/docker/devenv/Dockerfile @@ -41,6 +41,7 @@ RUN set -ex; \ python \ build-essential \ imagemagick \ + librsvg2-bin \ netpbm \ potrace \ webp \