From 2d16b9ce3b9b7ada354913ee9f81d3167498cc71 Mon Sep 17 00:00:00 2001 From: Tony McCrae Date: Mon, 16 Sep 2024 13:27:03 +0100 Subject: [PATCH] orientation field can be set from plain dimensions for images which have no orientation metadata. --- .../scala/com/gu/mediaservice/model/Asset.scala | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/common-lib/src/main/scala/com/gu/mediaservice/model/Asset.scala b/common-lib/src/main/scala/com/gu/mediaservice/model/Asset.scala index 0fba94caae..8e996309a3 100644 --- a/common-lib/src/main/scala/com/gu/mediaservice/model/Asset.scala +++ b/common-lib/src/main/scala/com/gu/mediaservice/model/Asset.scala @@ -27,13 +27,25 @@ object Asset { orientationMetadata.correctedDimensions(dimensions) } - val orientation = for { + val maybeCorrectedOrientation = for { dimensions <- dims orientationMetadata <- orientationMetadata } yield { orientationMetadata.correctedOrientation(dimensions) } + val maybeDimensionsOrientation = for { + dimensions <- dims + } yield { + if (dimensions.width < dimensions.height) { + "portrait" + } else { + "landscape" + } + } + + val maybeOrientation = Seq(maybeCorrectedOrientation, maybeDimensionsOrientation).flatten.headOption + Asset( file = s3Object.uri, size = Some(s3Object.size), @@ -42,7 +54,7 @@ object Asset { secureUrl = None, orientationMetadata = orientationMetadata, orientedDimensions = orientedDimensions, - orientation = orientation + orientation = maybeOrientation ) }