feat: invertierte Icon-Variante (schwarze Läuferin auf Weiß)
- make_app_icons.py um --inverted sowie --background/--figure erweitert - Master, Legacy- und Adaptive-Icons neu erzeugt; Monochrom bleibt alphabasiert für Androids Themed Icons
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 55 KiB |
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
Aufruf:
|
||||
python3 tools/make_app_icons.py pfad/zur/silhouette.png
|
||||
python3 tools/make_app_icons.py silhouette.png --inverted
|
||||
python3 tools/make_app_icons.py silhouette.png --background "#ffffff" --figure "#000000"
|
||||
|
||||
Die Vorlage muss eine Silhouette mit Alphakanal sein (Form = Deckkraft).
|
||||
Erzeugt:
|
||||
|
|
@ -14,7 +16,7 @@ Erzeugt:
|
|||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
|
|
@ -22,8 +24,8 @@ REPO = Path(__file__).resolve().parent.parent
|
|||
ICONS = REPO / "rinkplanner" / "assets" / "icons"
|
||||
ANDROID = ICONS / "android"
|
||||
|
||||
BACKGROUND = (11, 18, 32, 255) # #0b1220, passt zur App-Oberfläche
|
||||
SILHOUETTE = (255, 255, 255, 255)
|
||||
DEFAULT_BACKGROUND = "#0b1220" # passt zur App-Oberfläche
|
||||
DEFAULT_FIGURE = "#ffffff"
|
||||
MASTER_SIZE = 1024
|
||||
CORNER_RADIUS = 220
|
||||
|
||||
|
|
@ -49,57 +51,81 @@ def tinted(mask: Image.Image, color) -> Image.Image:
|
|||
return layer
|
||||
|
||||
|
||||
def rounded_background(size: int, radius: int) -> Image.Image:
|
||||
def hex_color(value: str) -> tuple:
|
||||
text = value.strip().lstrip("#")
|
||||
if len(text) == 6:
|
||||
text += "ff"
|
||||
if len(text) != 8:
|
||||
raise SystemExit(f"Ungültige Farbe: {value}")
|
||||
return tuple(int(text[i:i + 2], 16) for i in (0, 2, 4, 6))
|
||||
|
||||
|
||||
def rounded_background(size: int, radius: int, color: tuple) -> Image.Image:
|
||||
tile = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(tile)
|
||||
draw.rounded_rectangle((0, 0, size - 1, size - 1), radius=radius, fill=BACKGROUND)
|
||||
draw.rounded_rectangle((0, 0, size - 1, size - 1), radius=radius, fill=color)
|
||||
return tile
|
||||
|
||||
|
||||
def compose_master(mask: Image.Image) -> Image.Image:
|
||||
tile = rounded_background(MASTER_SIZE, CORNER_RADIUS)
|
||||
def compose_master(mask: Image.Image, background: tuple, figure: tuple) -> Image.Image:
|
||||
tile = rounded_background(MASTER_SIZE, CORNER_RADIUS, background)
|
||||
shape = fitted(mask, int(MASTER_SIZE * 0.74))
|
||||
position = (
|
||||
(MASTER_SIZE - shape.width) // 2,
|
||||
(MASTER_SIZE - shape.height) // 2,
|
||||
)
|
||||
tile.alpha_composite(tinted(shape, SILHOUETTE), position)
|
||||
tile.alpha_composite(tinted(shape, figure), position)
|
||||
return tile
|
||||
|
||||
|
||||
def compose_foreground(mask: Image.Image) -> Image.Image:
|
||||
def compose_foreground(mask: Image.Image, figure: tuple) -> Image.Image:
|
||||
canvas = Image.new("RGBA", (432, 432), (0, 0, 0, 0))
|
||||
shape = fitted(mask, int(432 * 0.60))
|
||||
position = ((432 - shape.width) // 2, (432 - shape.height) // 2)
|
||||
canvas.alpha_composite(tinted(shape, SILHOUETTE), position)
|
||||
canvas.alpha_composite(tinted(shape, figure), position)
|
||||
return canvas
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if len(sys.argv) != 2:
|
||||
raise SystemExit("Aufruf: python3 tools/make_app_icons.py <silhouette.png>")
|
||||
source = Path(sys.argv[1])
|
||||
parser = argparse.ArgumentParser(description="App-Icons aus einer Silhouette erzeugen.")
|
||||
parser.add_argument("source", help="PNG mit Alphakanal-Silhouette")
|
||||
parser.add_argument("--background", default=DEFAULT_BACKGROUND)
|
||||
parser.add_argument("--figure", default=DEFAULT_FIGURE)
|
||||
parser.add_argument(
|
||||
"--inverted",
|
||||
action="store_true",
|
||||
help="weißer Hintergrund, schwarze Figur",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
background = hex_color("#ffffff" if args.inverted else args.background)
|
||||
figure = hex_color("#000000" if args.inverted else args.figure)
|
||||
# Themed (monochrome) icons are tinted by the system; alpha is what counts.
|
||||
monochrome = hex_color("#ffffff")
|
||||
|
||||
source = Path(args.source)
|
||||
if not source.exists():
|
||||
raise SystemExit(f"Vorlage nicht gefunden: {source}")
|
||||
|
||||
ANDROID.mkdir(parents=True, exist_ok=True)
|
||||
mask = load_mask(source)
|
||||
|
||||
master = compose_master(mask)
|
||||
master = compose_master(mask, background, figure)
|
||||
master.save(ICONS / "app_icon.png")
|
||||
master.resize((192, 192), Image.LANCZOS).save(ANDROID / "ic_launcher_192.png")
|
||||
|
||||
foreground = compose_foreground(mask)
|
||||
foreground = compose_foreground(mask, figure)
|
||||
foreground.save(ANDROID / "ic_launcher_foreground_432.png")
|
||||
|
||||
background = Image.new("RGBA", (432, 432), BACKGROUND)
|
||||
background.save(ANDROID / "ic_launcher_background_432.png")
|
||||
background_layer = Image.new("RGBA", (432, 432), background)
|
||||
background_layer.save(ANDROID / "ic_launcher_background_432.png")
|
||||
|
||||
monochrome = Image.new("RGBA", (432, 432), (0, 0, 0, 0))
|
||||
monochrome.alpha_composite(foreground)
|
||||
monochrome.save(ANDROID / "ic_launcher_monochrome_432.png")
|
||||
monochrome_layer = Image.new("RGBA", (432, 432), (0, 0, 0, 0))
|
||||
monochrome_layer.alpha_composite(compose_foreground(mask, monochrome))
|
||||
monochrome_layer.save(ANDROID / "ic_launcher_monochrome_432.png")
|
||||
|
||||
print(f"Vorlage: {source}")
|
||||
print(f"Hintergrund: {args.background} Figur: {args.figure}")
|
||||
for path in sorted(ICONS.rglob("*.png")):
|
||||
print(f" {path.relative_to(REPO)}")
|
||||
|
||||
|
|
|
|||