feat: generate splash screens in icon script
This commit is contained in:
@@ -53,4 +53,43 @@ for (const [density, size] of Object.entries(FOREGROUND)) {
|
||||
console.log(`${density}: 前景 ${size}(内容 ${inner})`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动图尺寸,背景铺图标底色,中间放 logo
|
||||
*
|
||||
* 键为 drawable 目录名,值为画布宽高
|
||||
*/
|
||||
const SPLASH = {
|
||||
"drawable": [480, 320],
|
||||
"drawable-land-mdpi": [480, 320],
|
||||
"drawable-land-hdpi": [800, 480],
|
||||
"drawable-land-xhdpi": [1280, 720],
|
||||
"drawable-land-xxhdpi": [1600, 960],
|
||||
"drawable-land-xxxhdpi": [1920, 1280],
|
||||
"drawable-port-mdpi": [320, 480],
|
||||
"drawable-port-hdpi": [480, 800],
|
||||
"drawable-port-xhdpi": [720, 1280],
|
||||
"drawable-port-xxhdpi": [960, 1600],
|
||||
"drawable-port-xxxhdpi": [1280, 1920]
|
||||
};
|
||||
|
||||
/** logo 占短边的比例 */
|
||||
const SPLASH_LOGO_RATIO = 0.28;
|
||||
|
||||
for (const [dir, [width, height]] of Object.entries(SPLASH)) {
|
||||
const logo = Math.round(Math.min(width, height) * SPLASH_LOGO_RATIO);
|
||||
const scaled = await sharp(SOURCE).resize(logo, logo, { fit: "cover" }).png().toBuffer();
|
||||
await sharp({
|
||||
create: { width, height, channels: 3, background: { r: data[0], g: data[1], b: data[2] } }
|
||||
})
|
||||
.composite([{
|
||||
input: scaled,
|
||||
top: Math.round((height - logo) / 2),
|
||||
left: Math.round((width - logo) / 2)
|
||||
}])
|
||||
.png()
|
||||
.toFile(`${RES}/${dir}/splash.png`);
|
||||
|
||||
console.log(`${dir}: ${width}x${height},logo ${logo}`);
|
||||
}
|
||||
|
||||
console.log("完成");
|
||||
|
||||
Reference in New Issue
Block a user