Skip to content

Commit e4a3edb

Browse files
committed
Faster method for combining image files
Using the create() syntax caused us to create an unnecessary base image upon which we overlaid our pieces. By instead starting with one of our pieces, we can remove a step and some CPU cycles.
1 parent 8ede428 commit e4a3edb

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/lib/imaging.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ const maxSize = 400;
88
export const parseSize = parseSizeFactory(minSize, maxSize);
99

1010
export const combine = (face: Face) =>
11-
sharp({
12-
create: {
13-
width: maxSize,
14-
height: maxSize,
15-
channels: 4,
16-
background: face.color,
17-
},
18-
}).composite([
19-
{ input: face.eyes },
20-
{ input: face.mouth },
21-
{ input: face.nose },
22-
]);
11+
sharp(face.eyes)
12+
.composite([{ input: face.mouth }, { input: face.nose }])
13+
.flatten({ background: face.color });
2314

2415
export const resize = (rawSize: string) => {
2516
const size = parseSize(rawSize);

0 commit comments

Comments
 (0)