Skip to content

Commit

Permalink
feat(tiler-sharp): do not recompress intermediate tiffs
Browse files Browse the repository at this point in the history
Without a .raw() the sharp.toBuffer() will compress the image back into the input format which is mostly webp, this reduces tile creation time by approx 25% for my simple tests
  • Loading branch information
blacha committed Aug 4, 2023
1 parent 05ee834 commit 1adab49
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/tiler-sharp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,20 @@ export class TileMakerSharp implements TileMaker {

if (crop) sharp.extract({ top: crop.y, left: crop.x, width: crop.width, height: crop.height });

return { input: await sharp.toBuffer(), top: comp.y, left: comp.x };
const width = crop?.width ?? resize?.width ?? extract?.width ?? 256;
const height = crop?.height ?? resize?.height ?? extract?.height ?? 256;
const buf = await sharp.raw().toBuffer();
const channels = (buf.length / (width * height)) as 1 | 2 | 3 | 4;
return {
input: buf,
top: comp.y,
left: comp.x,
raw: {
width,
height,
channels,
},
};
}

private createImage(background: Sharp.RGBA): Sharp.Sharp {
Expand Down

0 comments on commit 1adab49

Please sign in to comment.