修改图标
This commit is contained in:
+15
-12
@@ -7,7 +7,7 @@ import sharp from "sharp";
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const projectRoot = path.resolve(__dirname, "..");
|
||||
const sourceIconPath = path.join(projectRoot, "icon.png");
|
||||
const sourceIconPath = path.join(projectRoot, "app", "icon.png");
|
||||
const pwaOutputDir = path.join(projectRoot, "public", "pwa");
|
||||
|
||||
const androidResArg = process.argv.find((arg) =>
|
||||
@@ -25,16 +25,19 @@ function createCircleMask(size) {
|
||||
`);
|
||||
}
|
||||
|
||||
async function writePng(size, outputPath) {
|
||||
await sharp(sourceIconPath).resize(size, size).png().toFile(outputPath);
|
||||
async function writeWebp(size, outputPath) {
|
||||
await sharp(sourceIconPath)
|
||||
.resize(size, size)
|
||||
.webp({ quality: 88, effort: 6 })
|
||||
.toFile(outputPath);
|
||||
}
|
||||
|
||||
async function writeMaskablePng(size, outputPath) {
|
||||
async function writeMaskableWebp(size, outputPath) {
|
||||
const foreground = await sharp(sourceIconPath)
|
||||
.resize(Math.round(size * 0.82), Math.round(size * 0.82), {
|
||||
fit: "contain",
|
||||
})
|
||||
.png()
|
||||
.webp({ quality: 88, effort: 6 })
|
||||
.toBuffer();
|
||||
|
||||
await sharp({
|
||||
@@ -51,7 +54,7 @@ async function writeMaskablePng(size, outputPath) {
|
||||
gravity: "center",
|
||||
},
|
||||
])
|
||||
.png()
|
||||
.webp({ quality: 88, effort: 6 })
|
||||
.toFile(outputPath);
|
||||
}
|
||||
|
||||
@@ -92,15 +95,15 @@ async function writeAndroidIcons(resDir) {
|
||||
await mkdir(pwaOutputDir, { recursive: true });
|
||||
|
||||
await Promise.all([
|
||||
writePng(192, path.join(pwaOutputDir, "icon-192x192.png")),
|
||||
writePng(512, path.join(pwaOutputDir, "icon-512x512.png")),
|
||||
writePng(180, path.join(pwaOutputDir, "apple-touch-icon.png")),
|
||||
writePng(96, path.join(pwaOutputDir, "badge-96x96.png")),
|
||||
writeMaskablePng(512, path.join(pwaOutputDir, "icon-maskable-512x512.png")),
|
||||
writeWebp(192, path.join(pwaOutputDir, "icon-192x192.webp")),
|
||||
writeWebp(512, path.join(pwaOutputDir, "icon-512x512.webp")),
|
||||
writeWebp(180, path.join(pwaOutputDir, "apple-touch-icon.webp")),
|
||||
writeWebp(96, path.join(pwaOutputDir, "badge-96x96.webp")),
|
||||
writeMaskableWebp(512, path.join(pwaOutputDir, "icon-maskable-512x512.webp")),
|
||||
]);
|
||||
|
||||
if (androidResDir) {
|
||||
await writeAndroidIcons(androidResDir);
|
||||
}
|
||||
|
||||
console.log("Icons generated successfully.");
|
||||
console.log("Icons generated successfully.");
|
||||
|
||||
Reference in New Issue
Block a user