Give a more sensible default crop in the post image picker (related #39)

This commit is contained in:
Paul Frazee 2023-01-17 18:35:37 -06:00
parent fb334b1b3f
commit bccc8a64d0
3 changed files with 47 additions and 6 deletions

View file

@ -112,3 +112,19 @@ export async function compressIfNeeded(
maxSize,
})
}
export interface Dim {
width: number
height: number
}
export function scaleDownDimensions(dim: Dim, max: Dim): Dim {
if (dim.width < max.width && dim.height < max.height) {
return dim
}
let wScale = dim.width > max.width ? max.width / dim.width : 1
let hScale = dim.height > max.height ? max.height / dim.height : 1
if (wScale < hScale) {
return {width: dim.width * wScale, height: dim.height * wScale}
}
return {width: dim.width * hScale, height: dim.height * hScale}
}