mirror of
https://github.com/kogakure/website-astro-stefanimhoff.de.git
synced 2026-02-03 12:05:28 +00:00
feat: generate cover thumbnails
This commit is contained in:
committed by
Stefan Imhoff
parent
da1c4bbd22
commit
3c354d937d
29
thumbnail-generate.cjs
Normal file
29
thumbnail-generate.cjs
Normal file
@@ -0,0 +1,29 @@
|
||||
const sharp = require('sharp');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const inputFolder = './public/assets/images/cover/';
|
||||
const outputFolder = './public/assets/images/thumbnail/';
|
||||
const resizeSize = { width: 500, height: 500 };
|
||||
|
||||
fs.readdir(inputFolder, async (err, files) => {
|
||||
if (err) throw err;
|
||||
for (const file of files) {
|
||||
if (/\.(webp|png|jpg|jpeg)$/i.test(file)) {
|
||||
const inputImagePath = path.join(inputFolder, file);
|
||||
const outputFilename = path.parse(file).name + '.jpg';
|
||||
const outputImagePath = path.join(outputFolder, outputFilename);
|
||||
|
||||
await sharp(inputImagePath)
|
||||
.resize({
|
||||
width: resizeSize.width,
|
||||
height: resizeSize.height,
|
||||
fit: 'cover',
|
||||
})
|
||||
.jpeg({ quality: 70 })
|
||||
.toFile(outputImagePath);
|
||||
|
||||
console.log(`Generated: ${outputFilename}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user