audiobookshelf/server/utils/resizeImage.js

16 lines
329 B
JavaScript
Raw Normal View History

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;