fix(web): show w x h correctly when media is rotated ()

This commit is contained in:
Jason Rasmussen 2024-05-13 16:03:36 -04:00 committed by GitHub
parent 5985f72643
commit b7ebf3152f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 5 deletions
web/src/lib/utils

View file

@ -218,14 +218,18 @@ function isRotated270CW(orientation: number) {
return orientation === 7 || orientation === 8 || orientation === -90;
}
export function isFlipped(orientation?: string | null) {
const value = Number(orientation);
return value && (isRotated270CW(value) || isRotated90CW(value));
}
/**
* Returns aspect ratio for the asset
*/
export function getAssetRatio(asset: AssetResponseDto) {
let height = asset.exifInfo?.exifImageHeight || 235;
let width = asset.exifInfo?.exifImageWidth || 235;
const orientation = Number(asset.exifInfo?.orientation);
if (orientation && (isRotated90CW(orientation) || isRotated270CW(orientation))) {
if (isFlipped(asset.exifInfo?.orientation)) {
[width, height] = [height, width];
}
return { width, height };