i'd like to slice an image into 2 (bottom half + top half)
Hello, if I've understood you correctly, a combination of metadata and extract should help here, something like (untested):
sharp(input)
.metadata()
.then(({ width, height }) => {
const halfHeight = Math.round(height / 2);
return [
sharp(input)
.extract({ top: 0, left: 0, width, height: halfHeight })
.toBuffer(),
sharp(input)
.extract({ top: halfHeight, left: 0, width, height: height - halfHeight })
.toBuffer()
];
})
.then(([upper, lower]) => { ... });
Hope this helped. Feel free to re-open with more details if not.
Most helpful comment
Hello, if I've understood you correctly, a combination of metadata and extract should help here, something like (untested):