Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created February 9, 2025 14:01
Show Gist options
  • Save tluyben/7eff63a240b889394007e1cc920c7015 to your computer and use it in GitHub Desktop.
Save tluyben/7eff63a240b889394007e1cc920c7015 to your computer and use it in GitHub Desktop.
Convert script for svg -> png
const sharp = require("sharp");
const fs = require("fs/promises");
const sizes = [16, 48, 128];
async function convertIcons() {
try {
await fs.mkdir("dist/assets", { recursive: true });
for (const size of sizes) {
await sharp("assets/icon.svg")
.resize(size, size)
.png()
.toFile(`dist/assets/icon${size}.png`);
}
console.log("Icons converted successfully");
} catch (error) {
console.error("Error converting icons:", error);
process.exit(1);
}
}
convertIcons();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment