Skip to content

Commit 69e7310

Browse files
committed
Use sizing functions from avatars-utils
1 parent a57efe7 commit 69e7310

File tree

2 files changed

+2
-42
lines changed

2 files changed

+2
-42
lines changed

src/lib/imaging.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
import sharp from 'sharp';
2+
import { parseSizeFactory } from 'avatars-utils';
23
import { Face } from './FaceFactory';
34

4-
export type Size = { height: number; width: number };
5-
65
const minSize = 40;
76
const maxSize = 400;
87

9-
const clamp = (num: number): number => {
10-
return Math.min(Math.max(num, minSize), maxSize);
11-
};
12-
13-
export const parseSize = (rawSize: string = ''): Size => {
14-
const [rawWidth, rawHeight] = rawSize.toLowerCase().split('x');
15-
const width = clamp(Number(rawWidth) || maxSize);
16-
const height = Number(rawHeight)
17-
? clamp(Number(rawHeight) || maxSize)
18-
: width;
19-
20-
return { width, height };
21-
};
8+
export const parseSize = parseSizeFactory(minSize, maxSize);
229

2310
export const combine = (face: Face) =>
2411
sharp({

test/lib/imaging.test.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)