Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

enhancement: image compression #227

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions image-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@ if (fs.existsSync(targetDir))
console.log(`Old directory removed: ${ targetDir }`);
}

const allowedFormats = [".png", ".jpg", ".jpeg", ".webp"];
const allowedFormats = [".png", ".jpg", ".jpeg", ".webp", ".tiff", ".bmp"];

async function convertAndCopyImage(imagePath, targetPath)
{
const ext = path.extname(imagePath).toLowerCase();

if (ext === ".avif")
if (ext === ".avif" || ext === ".svg" || ext === ".gif" || ext === ".ico")
{
await fs.copy(imagePath, targetPath);
console.log(`Copied: ${ targetPath }`);
} else if (ext === ".svg")
{
await fs.copy(imagePath, targetPath);
console.log(`Copied: ${ targetPath }`);
} else if (allowedFormats.includes(ext))
}
else if (allowedFormats.includes(ext))
{
await sharp(imagePath)
.toFormat("avif", { quality: ExpectedQuality })
Expand Down