Skip to content

Instantly share code, notes, and snippets.

@yukin01
Last active May 23, 2019 06:33
Show Gist options
  • Save yukin01/73a43bec015b355cfd1c5e6479957979 to your computer and use it in GitHub Desktop.
Save yukin01/73a43bec015b355cfd1c5e6479957979 to your computer and use it in GitHub Desktop.
1024 * 1024 を超えないようにリサイズ(トリミングなし、拡大なし)
const sharp = require('sharp')
const path = require('path')
const filePath = './image.png'
const fileName = path.basename(filePath, path.extname(filePath))
sharp(filePath)
.resize(1024, 1024, {
fit: sharp.fit.inside,
withoutEnlargement: true
})
.jpeg()
.toFile(`output-${Date.now()}-${fileName}.jpg`, (err, info)=>{
if(err){
throw err
}
console.log(info)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment