Review changes batch 6 of 6

This commit is contained in:
2026-07-20 06:52:33 +08:00
parent db97d3da27
commit 5a31a75da0
160 changed files with 9206 additions and 572 deletions
@@ -0,0 +1,51 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import sharp from 'sharp'
const scriptDirectory = path.dirname(fileURLToPath(import.meta.url))
const projectRoot = path.resolve(scriptDirectory, '..', '..')
const sourcePath = path.join(projectRoot, 'static', 'assets', 'modules', 'genealogy', 'opaque', 'g01-empty-panel.png')
const outputPath = path.join(projectRoot, 'static', 'assets', 'modules', 'genealogy', 'transparent', 'g01-empty-panel-frame.png')
const borderBand = 110
const { data, info } = await sharp(sourcePath)
.ensureAlpha()
.raw()
.toBuffer({ resolveWithObject: true })
for (let y = 0; y < info.height; y += 1) {
for (let x = 0; x < info.width; x += 1) {
const offset = (y * info.width + x) * info.channels
const red = data[offset]
const green = data[offset + 1]
const blue = data[offset + 2]
const alpha = data[offset + 3]
const distanceToEdge = Math.min(x, y, info.width - 1 - x, info.height - 1 - y)
const isWarmGold = red > green
&& green > blue
&& red - green >= 15
&& green - blue >= 12
&& red - blue >= 35
&& red < 245
&& blue < 180
if (distanceToEdge >= borderBand || !isWarmGold) {
data[offset + 3] = 0
continue
}
const edgeAlpha = Math.max(0, Math.min(255, (red - blue - 25) * 6))
data[offset + 3] = Math.min(alpha, edgeAlpha)
}
}
await sharp(data, {
raw: {
width: info.width,
height: info.height,
channels: info.channels
}
}).png().toFile(outputPath)
process.stdout.write(`BUILT ${path.relative(projectRoot, outputPath)}\n`)
@@ -0,0 +1,61 @@
from __future__ import annotations
import hashlib
import json
from pathlib import Path
from PIL import Image
ROOT = Path(__file__).resolve().parents[2]
MANIFEST = ROOT / "design-pipeline/manifests/module-page-backgrounds.json"
def sha256(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as stream:
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def normalize(source: Path, output: Path, width: int, height: int) -> None:
with Image.open(source) as image:
image = image.convert("RGB")
scale = max(width / image.width, height / image.height)
resized = image.resize(
(round(image.width * scale), round(image.height * scale)),
Image.Resampling.LANCZOS,
)
left = max(0, (resized.width - width) // 2)
top = max(0, (resized.height - height) // 2)
normalized = resized.crop((left, top, left + width, top + height))
output.parent.mkdir(parents=True, exist_ok=True)
normalized.save(output, format="PNG", optimize=True)
def main() -> None:
manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
width = int(manifest["width"])
height = int(manifest["height"])
report = []
for item in manifest["backgrounds"]:
source = ROOT / item["source"]
output = ROOT / item["output"]
if not source.is_file():
raise FileNotFoundError(source)
normalize(source, output, width, height)
report.append(
{
"module": item["module"],
"source": item["source"],
"output": item["output"],
"size": [width, height],
"sha256": sha256(output),
}
)
print(json.dumps(report, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()