I want to resize image to get 2 things: the resized data, and resized image metadata, using below code:
// inputFile metatada: {width: 1000, height: 800, ...}
const pipeline = sharp(inputFile)
.resize(300,300)
.max()
return Promise.all([
pipeline.clone().metadata(),
pipeline.clone().toBuffer()
]).then(values=>{
console.log(values[0])
// the metatada after resize, not changed???
// {width: 1000, height: 800, ...}
})
Is but the values[0] part of resized metadata still not changed, is that the issue of my code or the pipeline?
Hello, the resolveWithObject option of toBuffer will include post-resize metadata when resolving the Promise.
sharp(inputFile)
.resize(300, 300)
.max()
.toBuffer({ resolveWithObject: true })
.then(values => {
console.log(values.info);
});
It's worked! The problem solved. Thank you!
Most helpful comment
Hello, the resolveWithObject option of
toBufferwill include post-resize metadata when resolving the Promise.