压缩图片
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 538 KiB After Width: | Height: | Size: 510 KiB |
|
Before Width: | Height: | Size: 574 KiB After Width: | Height: | Size: 530 KiB |
|
Before Width: | Height: | Size: 672 KiB After Width: | Height: | Size: 632 KiB |
|
Before Width: | Height: | Size: 627 KiB After Width: | Height: | Size: 594 KiB |
|
Before Width: | Height: | Size: 960 KiB After Width: | Height: | Size: 908 KiB |
|
Before Width: | Height: | Size: 902 KiB After Width: | Height: | Size: 865 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 820 KiB After Width: | Height: | Size: 768 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 3.1 MiB After Width: | Height: | Size: 2.9 MiB |
|
Before Width: | Height: | Size: 648 KiB After Width: | Height: | Size: 623 KiB |
|
Before Width: | Height: | Size: 714 KiB After Width: | Height: | Size: 683 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 874 KiB After Width: | Height: | Size: 846 KiB |
|
Before Width: | Height: | Size: 567 KiB After Width: | Height: | Size: 557 KiB |
|
Before Width: | Height: | Size: 620 KiB After Width: | Height: | Size: 592 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 928 KiB After Width: | Height: | Size: 860 KiB |
|
Before Width: | Height: | Size: 674 KiB After Width: | Height: | Size: 655 KiB |
|
Before Width: | Height: | Size: 565 KiB After Width: | Height: | Size: 539 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1015 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 1011 KiB After Width: | Height: | Size: 989 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 740 KiB After Width: | Height: | Size: 718 KiB |
|
Before Width: | Height: | Size: 877 KiB After Width: | Height: | Size: 863 KiB |
|
Before Width: | Height: | Size: 650 KiB After Width: | Height: | Size: 619 KiB |
|
Before Width: | Height: | Size: 520 KiB After Width: | Height: | Size: 498 KiB |
|
Before Width: | Height: | Size: 930 KiB After Width: | Height: | Size: 895 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 973 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 693 KiB After Width: | Height: | Size: 663 KiB |
|
Before Width: | Height: | Size: 627 KiB After Width: | Height: | Size: 606 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 709 KiB After Width: | Height: | Size: 680 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 939 KiB After Width: | Height: | Size: 875 KiB |
|
Before Width: | Height: | Size: 576 KiB After Width: | Height: | Size: 558 KiB |
|
Before Width: | Height: | Size: 616 KiB After Width: | Height: | Size: 586 KiB |
|
Before Width: | Height: | Size: 733 KiB After Width: | Height: | Size: 688 KiB |
|
Before Width: | Height: | Size: 525 KiB After Width: | Height: | Size: 493 KiB |
|
Before Width: | Height: | Size: 670 KiB After Width: | Height: | Size: 656 KiB |
|
Before Width: | Height: | Size: 682 KiB After Width: | Height: | Size: 623 KiB |
|
Before Width: | Height: | Size: 644 KiB After Width: | Height: | Size: 551 KiB |
|
Before Width: | Height: | Size: 975 KiB After Width: | Height: | Size: 794 KiB |
|
Before Width: | Height: | Size: 512 KiB After Width: | Height: | Size: 476 KiB |
|
Before Width: | Height: | Size: 866 KiB After Width: | Height: | Size: 695 KiB |
|
Before Width: | Height: | Size: 809 KiB After Width: | Height: | Size: 646 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 908 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 967 KiB |
@ -52,6 +52,11 @@ async function compressImage(filePath) {
|
||||
|
||||
await pipeline.toFile(outputPath);
|
||||
|
||||
// Verify compressed file was created
|
||||
if (!fs.existsSync(outputPath)) {
|
||||
throw new Error(`Compressed file was not created: ${outputPath}`);
|
||||
}
|
||||
|
||||
const compressedSize = fs.statSync(outputPath).size;
|
||||
const originalSizeMB = originalSize / (1024 * 1024);
|
||||
const compressedSizeMB = compressedSize / (1024 * 1024);
|
||||
@ -92,7 +97,7 @@ async function main() {
|
||||
// Find all image files
|
||||
const imageFiles = [];
|
||||
for (const ext of extensions) {
|
||||
const pattern = path.join(STATIC_DIR, '**', `*${ext}`);
|
||||
const pattern = path.join(STATIC_DIR, '**', `*${ext}`).replace(/\\/g, '/');
|
||||
const { globSync } = require('glob');
|
||||
const files = globSync(pattern, { nodir: true });
|
||||
imageFiles.push(...files);
|
||||
|
||||