Last active
May 23, 2019 06:33
-
-
Save yukin01/73a43bec015b355cfd1c5e6479957979 to your computer and use it in GitHub Desktop.
1024 * 1024 を超えないようにリサイズ(トリミングなし、拡大なし)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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