Skip to content

Commit

Permalink
orientation field can be set from plain dimensions for images which h…
Browse files Browse the repository at this point in the history
…ave no orientation metadata.
  • Loading branch information
tonytw1 committed Oct 12, 2024
1 parent e309987 commit 373aea4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions common-lib/src/main/scala/com/gu/mediaservice/model/Asset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -42,7 +54,7 @@ object Asset {
secureUrl = None,
orientationMetadata = orientationMetadata,
orientedDimensions = orientedDimensions,
orientation = orientation
orientation = maybeOrientation
)
}

Expand Down

0 comments on commit 373aea4

Please sign in to comment.