Bri-Tunes/src/services/image.js

14 lines
494 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const sharp = require('sharp');
// Resize and center-crop an image to a 1:1 square at max 1000×1000, saved as JPEG.
// inputPath — absolute path of the source file (any format sharp supports)
// outputPath — absolute path for the output .jpg file
async function processCoverImage(inputPath, outputPath) {
await sharp(inputPath)
.resize(1000, 1000, { fit: 'cover', position: 'centre' })
.jpeg({ quality: 88 })
.toFile(outputPath);
}
module.exports = { processCoverImage };