34 lines
1.1 KiB
JavaScript
Executable File
34 lines
1.1 KiB
JavaScript
Executable File
const sharp = require('sharp');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const inputDir = './src/main/resources/static/zaklik-public-images'; // Folder z oryginalnymi obrazami
|
|
const outputDir = './src/main/resources/static/main-images/optimized-by-sharp'; // Folder do zapisu obrazów w nowych formatach
|
|
|
|
const formats = ['webp', 'avif'];
|
|
|
|
fs.readdir(inputDir, (err, files) => {
|
|
if (err) {
|
|
console.error('Error reading input directory:', err);
|
|
return;
|
|
}
|
|
|
|
files.forEach(file => {
|
|
const inputFile = path.join(inputDir, file);
|
|
const fileName = path.parse(file).name;
|
|
|
|
formats.forEach(format => {
|
|
const outputFile = path.join(outputDir, `${fileName}.${format}`);
|
|
sharp(inputFile)
|
|
.toFormat(format, { quality: 80 })
|
|
.toFile(outputFile, (err, info) => {
|
|
if (err) {
|
|
console.error(`Error converting ${file} to ${format}:`, err);
|
|
} else {
|
|
console.log(`Converted ${file} to ${format} format.`);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|