From 515cbf7befb3d5af188ba86549fe4da57f3b1cee Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 5 Aug 2025 19:30:01 +0200 Subject: [PATCH] :bug: Revert orientation detection on media --- backend/src/app/media.clj | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 51649db3d5..710275a542 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -10,7 +10,6 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.common.exceptions :as ex] - [app.common.logging :as l] [app.common.media :as cm] [app.common.schema :as sm] [app.common.schema.openapi :as-alias oapi] @@ -22,7 +21,6 @@ [buddy.core.bytes :as bb] [buddy.core.codecs :as bc] [clojure.java.shell :as sh] - [clojure.string] [clojure.xml :as xml] [cuerdas.core :as str] [datoteka.fs :as fs] @@ -217,23 +215,6 @@ {:width (int width) :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 [{:keys [input] :as params}] (let [{:keys [path mtype] :as input} (check-input input)] @@ -253,17 +234,13 @@ :code :media-type-mismatch :hint (str "Seems like you are uploading a file whose content does not match the extension." "Expected: " mtype ". Got: " mtype'))) - (let [{:keys [width height]} - (or (get-dimensions-with-orientation (str path)) - (do - (l/warn "Failed to read image dimensions with orientation; falling back to im4java" - {:path path}) - {:width (.getPageWidth instance) - :height (.getPageHeight instance)}))] - (assoc input - :width width - :height height - :ts (dt/now))))))) + ;; For an animated GIF, getImageWidth/Height returns the delta size of one frame (if no frame given + ;; it returns size of the last one), whereas getPageWidth/Height always return the full size of + ;; any frame. + (assoc input + :width (.getPageWidth instance) + :height (.getPageHeight instance) + :ts (dt/now)))))) (defmethod process-error org.im4java.core.InfoException [error]