const sharp = require('sharp');


function makeThumb(src, dest, size) {
  size = parseInt(size);
  return new Promise(function (done, reject) {
    sharp(src)
      .resize(size)
      .flatten({ background: { r: 255, g: 255, b: 255 } })
      .toFile(dest, err => {
        if (err) reject(err);
        else done(dest);
      })
  });

}


module.exports = {
  makeThumb,
}


async function testMakeThumb() {
  let src = '/Users/chengen/www/coloring/thumbs/v2/page/original/5c88af4a52b5b2c9a4dc4ff9.png'
  let dest = './out.png'
  await makeThumb(src, dest, 200)
}

if (require.main == module) {
  testMakeThumb().catch(console.error);
}