mirror of
https://github.com/penpot/penpot.git
synced 2026-09-10 05:58:47 +00:00
🐛 Revert orientation detection on media
This commit is contained in:
parent
c320cbc47b
commit
515cbf7bef
@ -10,7 +10,6 @@
|
|||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.logging :as l]
|
|
||||||
[app.common.media :as cm]
|
[app.common.media :as cm]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.schema.openapi :as-alias oapi]
|
[app.common.schema.openapi :as-alias oapi]
|
||||||
@ -22,7 +21,6 @@
|
|||||||
[buddy.core.bytes :as bb]
|
[buddy.core.bytes :as bb]
|
||||||
[buddy.core.codecs :as bc]
|
[buddy.core.codecs :as bc]
|
||||||
[clojure.java.shell :as sh]
|
[clojure.java.shell :as sh]
|
||||||
[clojure.string]
|
|
||||||
[clojure.xml :as xml]
|
[clojure.xml :as xml]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.fs :as fs]
|
[datoteka.fs :as fs]
|
||||||
@ -217,23 +215,6 @@
|
|||||||
{:width (int width)
|
{:width (int width)
|
||||||
:height (int height)})))]))
|
:height (int height)})))]))
|
||||||
|
|
||||||
(defn- get-dimensions-with-orientation [^String path]
|
|
||||||
;; Image magick doesn't give info about exif rotation so we use the identify command
|
|
||||||
;; If we are processing an animated gif we use the first frame with -scene 0
|
|
||||||
(let [dim-result (sh/sh "identify" "-format" "%w %h\n" path)
|
|
||||||
orient-result (sh/sh "identify" "-format" "%[EXIF:Orientation]\n" path)]
|
|
||||||
(if (and (= 0 (:exit dim-result))
|
|
||||||
(= 0 (:exit orient-result)))
|
|
||||||
(let [[w h] (-> (:out dim-result)
|
|
||||||
str/trim
|
|
||||||
(clojure.string/split #"\s+")
|
|
||||||
(->> (mapv #(Integer/parseInt %))))
|
|
||||||
orientation (-> orient-result :out str/trim)]
|
|
||||||
(case orientation
|
|
||||||
("6" "8") {:width h :height w} ; Rotated 90 or 270 degrees
|
|
||||||
{:width w :height h})) ; Normal or unknown orientation
|
|
||||||
nil)))
|
|
||||||
|
|
||||||
(defmethod process :info
|
(defmethod process :info
|
||||||
[{:keys [input] :as params}]
|
[{:keys [input] :as params}]
|
||||||
(let [{:keys [path mtype] :as input} (check-input input)]
|
(let [{:keys [path mtype] :as input} (check-input input)]
|
||||||
@ -253,17 +234,13 @@
|
|||||||
: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 (str "Seems like you are uploading a file whose content does not match the extension."
|
||||||
"Expected: " mtype ". Got: " mtype')))
|
"Expected: " mtype ". Got: " mtype')))
|
||||||
(let [{:keys [width height]}
|
;; For an animated GIF, getImageWidth/Height returns the delta size of one frame (if no frame given
|
||||||
(or (get-dimensions-with-orientation (str path))
|
;; it returns size of the last one), whereas getPageWidth/Height always return the full size of
|
||||||
(do
|
;; any frame.
|
||||||
(l/warn "Failed to read image dimensions with orientation; falling back to im4java"
|
(assoc input
|
||||||
{:path path})
|
:width (.getPageWidth instance)
|
||||||
{:width (.getPageWidth instance)
|
:height (.getPageHeight instance)
|
||||||
:height (.getPageHeight instance)}))]
|
:ts (dt/now))))))
|
||||||
(assoc input
|
|
||||||
:width width
|
|
||||||
:height height
|
|
||||||
:ts (dt/now)))))))
|
|
||||||
|
|
||||||
(defmethod process-error org.im4java.core.InfoException
|
(defmethod process-error org.im4java.core.InfoException
|
||||||
[error]
|
[error]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user