27 lines
618 B
JavaScript
27 lines
618 B
JavaScript
const sharp = require("sharp");
|
|
|
|
async function makeDetailWebp(inputBuffer) {
|
|
return sharp(inputBuffer)
|
|
.rotate()
|
|
.resize({ width: 1200, withoutEnlargement: true })
|
|
.webp({ quality: 80 })
|
|
.toBuffer();
|
|
}
|
|
|
|
async function makeThumbWebp(inputBuffer) {
|
|
return sharp(inputBuffer)
|
|
.rotate()
|
|
.resize({ width: 400, withoutEnlargement: true })
|
|
.webp({ quality: 75 })
|
|
.toBuffer();
|
|
}
|
|
|
|
async function makeWebp(inputBuffer, { quality = 80 } = {}) {
|
|
return sharp(inputBuffer)
|
|
.rotate()
|
|
.webp({ quality })
|
|
.toBuffer();
|
|
}
|
|
|
|
module.exports = { makeDetailWebp, makeThumbWebp, makeWebp };
|