Skip to content

Commit

Permalink
refactor: better way of getting width/height/channels
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Aug 6, 2023
1 parent 1adab49 commit 4ef44b1
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/tiler-sharp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,12 @@ export class TileMakerSharp implements TileMaker {

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

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;
const ret = await sharp.raw().toBuffer({ resolveWithObject: true });
return {
input: buf,
input: ret.data,
top: comp.y,
left: comp.x,
raw: {
width,
height,
channels,
},
raw: ret.info,
};
}

Expand Down

0 comments on commit 4ef44b1

Please sign in to comment.