Add:Cover image cache, resize & use webp image #223

This commit is contained in:
advplyr 2021-12-12 17:15:37 -06:00
parent d04f3450ec
commit ddf0fa72e8
14 changed files with 360 additions and 108 deletions

View file

@ -1,13 +1,13 @@
const sharp = require('sharp')
const fs = require('fs')
function resize(filePath, width, height) {
function resize(filePath, width, height, format = 'webp') {
const readStream = fs.createReadStream(filePath);
let sharpie = sharp()
sharpie.toFormat('jpeg')
sharpie.toFormat(format)
if (width || height) {
sharpie.resize(width, height)
sharpie.resize(width, height, { withoutEnlargement: true })
}
return readStream.pipe(sharpie)