mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
16 lines
376 B
JavaScript
16 lines
376 B
JavaScript
const sharp = require('sharp')
|
|
const fs = require('fs')
|
|
|
|
function resize(filePath, width, height, format = 'webp') {
|
|
const readStream = fs.createReadStream(filePath);
|
|
let sharpie = sharp()
|
|
sharpie.toFormat(format)
|
|
|
|
if (width || height) {
|
|
sharpie.resize(width, height, { withoutEnlargement: true })
|
|
}
|
|
|
|
return readStream.pipe(sharpie)
|
|
}
|
|
|
|
module.exports = resize; |