Go + PostgreSQL + Valkey backend (cmd/internal/migrations), uni-app mobile frontend, PC web (web/), admin console (admin/), Android WebView container (android_project/). Build artifacts, node_modules, local env and debug screenshots excluded.
101 lines
3.6 KiB
JavaScript
101 lines
3.6 KiB
JavaScript
// 生成创作 tab 图标(美篇式圆底加号):81x81
|
||
// 未选:米灰圆底 + 深灰加号;选中:黑圆底 + 白加号
|
||
const zlib = require('zlib');
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
const S = 64; // 画布尺寸(原 81 偏大遮挡字,现适配 64)
|
||
const SS = 3; // 超采样倍数(抗锯齿)
|
||
const R = 29; // 圆底半径
|
||
const BAR = 26; // 加号臂长
|
||
const THK = 8; // 臂厚
|
||
const RAD = 4; // 圆角半径
|
||
|
||
const CRC_TABLE = (() => {
|
||
const t = new Int32Array(256);
|
||
for (let n = 0; n < 256; n++) {
|
||
let c = n;
|
||
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
||
t[n] = c;
|
||
}
|
||
return t;
|
||
})();
|
||
|
||
function crc32(buf) {
|
||
let c = 0xffffffff;
|
||
for (let i = 0; i < buf.length; i++) c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
|
||
return (c ^ 0xffffffff) >>> 0;
|
||
}
|
||
|
||
function chunk(type, data) {
|
||
const len = Buffer.alloc(4);
|
||
len.writeUInt32BE(data.length);
|
||
const body = Buffer.concat([Buffer.from(type, 'ascii'), data]);
|
||
const crc = Buffer.alloc(4);
|
||
crc.writeUInt32BE(crc32(body));
|
||
return Buffer.concat([len, body, crc]);
|
||
}
|
||
|
||
/** 点是否在以 (cx,cy) 为中心的圆角条内 */
|
||
function inRoundedBar(px, py, cx, cy, len, thk, rad) {
|
||
const halfL = len / 2, halfT = thk / 2;
|
||
const dx = Math.abs(px - cx), dy = Math.abs(py - cy);
|
||
const ox = Math.max(dx - (halfL - rad), 0);
|
||
const oy = Math.max(dy - (halfT - rad), 0);
|
||
return dx <= halfL && dy <= halfT && ox * ox + oy * oy <= rad * rad;
|
||
}
|
||
|
||
function makeIcon(bg, fg) {
|
||
const c = (S - 1) / 2;
|
||
const rows = [];
|
||
for (let y = 0; y < S; y++) {
|
||
const row = Buffer.alloc(1 + S * 4); // filter byte 0 + RGBA
|
||
for (let x = 0; x < S; x++) {
|
||
let circleHits = 0;
|
||
let plusHits = 0;
|
||
for (let sy = 0; sy < SS; sy++) {
|
||
for (let sx = 0; sx < SS; sx++) {
|
||
const px = x + (sx + 0.5) / SS;
|
||
const py = y + (sy + 0.5) / SS;
|
||
const inCircle = (px - c) * (px - c) + (py - c) * (py - c) <= R * R;
|
||
if (!inCircle) continue;
|
||
circleHits++;
|
||
const inH = inRoundedBar(px, py, c, c, BAR, THK, RAD);
|
||
const inV = inRoundedBar(px, py, c, c, THK, BAR, RAD);
|
||
if (inH || inV) plusHits++;
|
||
}
|
||
}
|
||
const samples = SS * SS;
|
||
const circleA = circleHits / samples;
|
||
if (circleA <= 0) { row[1 + x * 4 + 3] = 0; continue; }
|
||
// 圆内混合:加号前景按覆盖度混入,圆底色兜底
|
||
const plusA = plusHits / samples;
|
||
const rr = Math.round(fg[0] * plusA + bg[0] * (1 - plusA));
|
||
const gg = Math.round(fg[1] * plusA + bg[1] * (1 - plusA));
|
||
const bb = Math.round(fg[2] * plusA + bg[2] * (1 - plusA));
|
||
const o = 1 + x * 4;
|
||
row[o] = rr; row[o + 1] = gg; row[o + 2] = bb;
|
||
row[o + 3] = Math.round(circleA * 255);
|
||
}
|
||
rows.push(row);
|
||
}
|
||
|
||
const ihdr = Buffer.alloc(13);
|
||
ihdr.writeUInt32BE(S, 0);
|
||
ihdr.writeUInt32BE(S, 4);
|
||
ihdr[8] = 8; // bit depth
|
||
ihdr[9] = 6; // RGBA
|
||
return Buffer.concat([
|
||
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
||
chunk('IHDR', ihdr),
|
||
chunk('IDAT', zlib.deflateSync(Buffer.concat(rows))),
|
||
chunk('IEND', Buffer.alloc(0)),
|
||
]);
|
||
}
|
||
|
||
const outDir = path.join(__dirname, '..', 'frontend', 'src', 'static', 'tabbar');
|
||
// 与原型模板完全一致:深黑圆底 #0F172A + 白加号
|
||
fs.writeFileSync(path.join(outDir, 'create.png'), makeIcon([15, 23, 42], [255, 255, 255]));
|
||
fs.writeFileSync(path.join(outDir, 'create-active.png'), makeIcon([15, 23, 42], [255, 255, 255]));
|
||
console.log('icons written to', outDir);
|