audiobookshelf/server/utils/resizeImage.js
2021-12-12 08:52:27 -08:00

16 lines
329 B
JavaScript

const sharp = require('sharp')
const fs = require('fs')
function resize(filePath, width, height) {
const readStream = fs.createReadStream(filePath);
let sharpie = sharp()
sharpie.toFormat('jpeg')
if (width || height) {
sharpie.resize(width, height)
}
return readStream.pipe(sharpie)
}
module.exports = resize;