diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-01-17 18:35:37 -0600 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2023-01-17 18:35:37 -0600 |
commit | bccc8a64d06310f91b607f2c0e175c26d42ff1fb (patch) | |
tree | 3463214497c071b1a9f5673c00a8e8694c2ddf0e /src/lib | |
parent | fb334b1b3f6176965e08868530e39cb48d767b3f (diff) | |
download | voidsky-bccc8a64d06310f91b607f2c0e175c26d42ff1fb.tar.zst |
Give a more sensible default crop in the post image picker (related #39)
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/images.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/images.ts b/src/lib/images.ts index f56308c49..6f0b6a4fc 100644 --- a/src/lib/images.ts +++ b/src/lib/images.ts @@ -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} +} |