From 3cb0e1b6eeac0b63dea8544e722acf31aacca046 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 2 Jul 2025 10:31:05 +0200 Subject: [PATCH] :bug: Fix exif rotation detection when auto-rotation isn't supported (#6818) --- backend/src/app/media.clj | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 27bcaecde9..51649db3d5 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -220,16 +220,18 @@ (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 [result (sh/sh "identify" "-auto-orient" "-format" "%w %h\n" path)] - (if (= 0 (:exit result)) - (let [tokens (-> (:out result) - str/trim - clojure.string/split-lines - first - (str/split #"\s+")) - [w h] (mapv #(Integer/parseInt %) tokens)] - {:width w - :height h}) + (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