debug print
This commit is contained in:
@@ -8,7 +8,6 @@ let
|
||||
priority = toString (containerCfg.extra.priority or 2147482647);
|
||||
logoSvgFileName = builtins.baseNameOf (toString mediaCfg.logo.svg);
|
||||
logoSvgMount = "/assets/${logoSvgFileName}";
|
||||
borderRadius = toString (containerCfg.extra.borderRadius or 16);
|
||||
ensureAttrSet = field: value:
|
||||
if builtins.isAttrs value then
|
||||
value
|
||||
@@ -73,7 +72,7 @@ let
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
import cairosvg
|
||||
from PIL import Image, ImageDraw
|
||||
from PIL import Image
|
||||
|
||||
LOGO_PATH = ${builtins.toJSON logoSvgMount}
|
||||
LISTEN_HOST = "0.0.0.0"
|
||||
@@ -114,10 +113,15 @@ let
|
||||
return candidates
|
||||
|
||||
def _profile_for_host(host):
|
||||
for candidate in _host_candidates(host):
|
||||
candidates = _host_candidates(host)
|
||||
print(f"favicon-profile host={host!r} candidates={candidates!r} mappings={list(MAPPINGS.keys())!r}")
|
||||
for candidate in candidates:
|
||||
profile = MAPPINGS.get(candidate)
|
||||
print(f"favicon-profile-check candidate={candidate!r} hit={profile is not None}")
|
||||
if profile:
|
||||
print(f"favicon-profile-match candidate={candidate!r} profile={profile!r}")
|
||||
return candidate, profile
|
||||
print(f"favicon-profile-default host={host!r} default={DEFAULT_PROFILE!r}")
|
||||
return None, DEFAULT_PROFILE
|
||||
|
||||
def _replace_logo_fill(svg, color):
|
||||
@@ -128,11 +132,6 @@ let
|
||||
flags=re.IGNORECASE,
|
||||
)
|
||||
|
||||
border_radius = str(${builtins.toJSON borderRadius}).strip()
|
||||
if not border_radius.endswith("px"):
|
||||
border_radius = f"{border_radius}px"
|
||||
border_radius_px = max(0, int(float(border_radius[:-2])))
|
||||
|
||||
def _colors(profile):
|
||||
profile = profile or {}
|
||||
return {
|
||||
@@ -140,26 +139,30 @@ let
|
||||
"fg": profile.get("fg") or profile.get("foreground") or DEFAULT_COLORS["fg"],
|
||||
}
|
||||
|
||||
def _add_background(svg, color):
|
||||
return re.sub(
|
||||
r"(<svg\\b[^>]*>)",
|
||||
rf'\\1<circle cx="64" cy="64" r="64" fill="{color}"/>',
|
||||
svg,
|
||||
count=1,
|
||||
flags=re.IGNORECASE,
|
||||
)
|
||||
|
||||
def _render_icon(colors):
|
||||
svg = LOGO_BYTES.decode("utf-8")
|
||||
svg = _replace_logo_fill(svg, colors["fg"])
|
||||
print(f"favicon-render fg={colors['fg']} bg={colors['bg']}")
|
||||
svg = _add_background(svg, colors["bg"])
|
||||
print(f"favicon-render fg={colors['fg']} bg={colors['bg']} mode=svg2png")
|
||||
|
||||
logo_png = cairosvg.svg2png(
|
||||
png = cairosvg.svg2png(
|
||||
bytestring=svg.encode("utf-8"),
|
||||
output_width=ASSET_SIZE,
|
||||
output_height=ASSET_SIZE,
|
||||
)
|
||||
output = BytesIO()
|
||||
with Image.new("RGBA", (ASSET_SIZE, ASSET_SIZE), (0, 0, 0, 0)) as canvas:
|
||||
ImageDraw.Draw(canvas).rounded_rectangle(
|
||||
(0, 0, ASSET_SIZE, ASSET_SIZE),
|
||||
radius=min(border_radius_px, ASSET_SIZE // 2),
|
||||
fill=colors["bg"],
|
||||
)
|
||||
with Image.open(BytesIO(logo_png)) as logo:
|
||||
canvas.alpha_composite(logo.convert("RGBA"))
|
||||
canvas.save(output, format="ICO", sizes=[(ASSET_SIZE, ASSET_SIZE)])
|
||||
with Image.open(BytesIO(png)) as image:
|
||||
with image.convert("RGBA") as rgba:
|
||||
rgba.save(output, format="ICO", sizes=[(ASSET_SIZE, ASSET_SIZE)])
|
||||
return output.getvalue()
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
Reference in New Issue
Block a user