Icônes PNG de l'écran d'accueil (make icons)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
342829bf93
commit
888aec1003
@@ -0,0 +1,38 @@
|
||||
// Génère les icônes PNG de l'app à partir des SVG de app/icons/ : iOS n'accepte
|
||||
// pas le SVG pour l'écran d'accueil, et Android en veut en 192 et 512 px.
|
||||
// Lancé par `make icons` dans l'image Docker de Playwright (Chromium dessine le
|
||||
// SVG, puis une capture à la taille exacte) :
|
||||
// node icons.cjs <dossier des icônes>
|
||||
// Les PNG produits sont commités : on ne relance ce script que si un SVG change.
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { chromium } = require("/tools/node_modules/playwright");
|
||||
|
||||
const dir = path.resolve(process.argv[2] ?? "app/icons");
|
||||
|
||||
/** Fichier produit, SVG source, côté en pixels. */
|
||||
const ICONS = [
|
||||
["icon-192.png", "icon.svg", 192],
|
||||
["icon-512.png", "icon.svg", 512],
|
||||
["icon-maskable-512.png", "icon-maskable.svg", 512],
|
||||
["apple-touch-icon.png", "icon.svg", 180],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
const browser = await chromium.launch();
|
||||
for (const [out, src, size] of ICONS) {
|
||||
const page = await browser.newPage({ viewport: { width: size, height: size }, deviceScaleFactor: 1 });
|
||||
const svg = fs.readFileSync(path.join(dir, src)).toString("base64");
|
||||
await page.setContent(`<style>html,body{margin:0}img{display:block;width:${size}px;height:${size}px}</style>` +
|
||||
`<img src="data:image/svg+xml;base64,${svg}" alt="">`);
|
||||
await page.locator("img").evaluate((img) => img.decode());
|
||||
await page.screenshot({ path: path.join(dir, out), clip: { x: 0, y: 0, width: size, height: size } });
|
||||
await page.close();
|
||||
console.log(`${out} : ${src} en ${size} px`);
|
||||
}
|
||||
await browser.close();
|
||||
})().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user