-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst.js
53 lines (46 loc) · 1.6 KB
/
st.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require("fs");
const sharp = require("sharp");
// Giriş ve çıkış dizinleri
const inputDirectory = "./input_images";
const outputDirectory = "./output_images";
// Boyutlandırma yapılandırması
const resizeWidth = 1920; // Dilediğiniz genişliği burada ayarlayın
const resizeHeight = null; // Dilediğiniz yüksekliği burada ayarlayın
// Kalite ayarları
const jpegQuality = 70; // JPEG kalitesi (0-100 arasında)
const pngQuality = 8; // PNG kalitesi (0-9 arasında)
// Çıkış dizini henüz varsa oluştur
if (!fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory);
}
// Giriş dizinindeki dosyaları oku
fs.readdir(inputDirectory, (err, files) => {
if (err) {
console.error("Giriş dizinini okurken hata oluştu:", err);
return;
}
// Her dosyayı işle
files.forEach((file) => {
const inputPath = `${inputDirectory}/${file}`;
const outputPath = `${outputDirectory}/${file}`;
const format = file.split(".").pop().toLowerCase();
// Orijinal görüntü oranını koruyarak boyutlandır ve kalite ayarlarını belirle
sharp(inputPath)
.rotate()
.resize(resizeWidth, resizeHeight, {
fit: sharp.fit.inside,
})
.toFormat(format === "png" ? "png" : "jpeg", {
quality: format === "png" ? pngQuality : jpegQuality,
})
.toFile(outputPath, (err) => {
if (err) {
console.error(`${file} işlenirken hata oluştu:`, err);
} else {
console.log(
`${file} boyutlandırıldı ve ${resizeWidth}x${resizeHeight} olarak kaydedildi.`
);
}
});
});
});