Sharp: metadata not changed after pipeline resize

Created on 16 Jul 2017  路  2Comments  路  Source: lovell/sharp

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?

question

Most helpful comment

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);
  });

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Andresmag picture Andresmag  路  3Comments

iq-dot picture iq-dot  路  3Comments

terbooter picture terbooter  路  3Comments

AVVS picture AVVS  路  3Comments

OleVik picture OleVik  路  3Comments