Initial commit
This commit is contained in:
98
tools/make_icons.py
Normal file
98
tools/make_icons.py
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Erzeugt die Symbole der Erweiterung.
|
||||
|
||||
Gezeichnet wird achtfach vergroessert und anschliessend heruntergerechnet -
|
||||
bei 42x42 Pixeln ist das der einzige Weg zu sauberen Kanten.
|
||||
|
||||
Aufruf: python3 tools/make_icons.py
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
SCALE = 8
|
||||
TARGET = 42
|
||||
BIG = TARGET * SCALE
|
||||
|
||||
PAPER = (255, 255, 255, 255)
|
||||
INK = (61, 56, 70, 255) # Rahmen und Trennlinie
|
||||
TEXT = (154, 153, 150, 255) # unveraenderter Text
|
||||
INSERT = (26, 95, 180, 255) # Einfuegung
|
||||
DELETE = (165, 29, 45, 255) # Loeschung
|
||||
|
||||
BLACK = (0, 0, 0, 255)
|
||||
WHITE = (255, 255, 255, 255)
|
||||
|
||||
# Zeilenraster: (y, Breite links, Breite rechts, Farbrolle rechts)
|
||||
ROWS = (
|
||||
(0.22, 1.00, 1.00, "equal"),
|
||||
(0.38, 1.00, 0.85, "insert"),
|
||||
(0.54, 1.00, 1.00, "equal"),
|
||||
(0.70, 1.00, 0.55, "delete"),
|
||||
)
|
||||
|
||||
|
||||
def draw(colors, border):
|
||||
img = Image.new("RGBA", (BIG, BIG), (0, 0, 0, 0))
|
||||
pen = ImageDraw.Draw(img)
|
||||
|
||||
margin = int(BIG * 0.09)
|
||||
box = (margin, margin, BIG - margin, BIG - margin)
|
||||
radius = int(BIG * 0.08)
|
||||
pen.rounded_rectangle(box, radius=radius, fill=colors["paper"],
|
||||
outline=colors["ink"], width=border)
|
||||
|
||||
middle = BIG // 2
|
||||
pen.line([(middle, margin + border), (middle, BIG - margin - border)],
|
||||
fill=colors["ink"], width=max(2, border // 2))
|
||||
|
||||
pad = int(BIG * 0.16)
|
||||
left_start, left_end = pad, middle - int(BIG * 0.06)
|
||||
right_start, right_end = middle + int(BIG * 0.06), BIG - pad
|
||||
height = int(BIG * 0.075)
|
||||
bar_radius = height // 2
|
||||
|
||||
for y_rel, w_left, w_right, role in ROWS:
|
||||
y = int(BIG * y_rel)
|
||||
span = left_end - left_start
|
||||
pen.rounded_rectangle(
|
||||
(left_start, y, left_start + int(span * w_left), y + height),
|
||||
radius=bar_radius, fill=colors["text"])
|
||||
|
||||
span = right_end - right_start
|
||||
pen.rounded_rectangle(
|
||||
(right_start, y, right_start + int(span * w_right), y + height),
|
||||
radius=bar_radius, fill=colors[role])
|
||||
|
||||
return img
|
||||
|
||||
|
||||
def save(img, path, size):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
img.resize((size, size), Image.LANCZOS).save(path, "PNG", optimize=True)
|
||||
print("%s %dx%d" % (path, size, size))
|
||||
|
||||
|
||||
def main():
|
||||
here = os.path.dirname(os.path.abspath(__file__))
|
||||
root = os.path.dirname(here)
|
||||
|
||||
normal = draw({"paper": PAPER, "ink": INK, "text": TEXT,
|
||||
"equal": TEXT, "insert": INSERT, "delete": DELETE},
|
||||
border=int(BIG * 0.022))
|
||||
|
||||
# Hoher Kontrast: nur Schwarz und Weiss, kraeftigerer Rahmen. Die
|
||||
# Unterscheidung der Zeilen traegt hier allein ueber die Laenge.
|
||||
contrast = draw({"paper": WHITE, "ink": BLACK, "text": BLACK,
|
||||
"equal": BLACK, "insert": BLACK, "delete": BLACK},
|
||||
border=int(BIG * 0.04))
|
||||
|
||||
save(normal, os.path.join(root, "icon", "synopse.png"), TARGET)
|
||||
save(contrast, os.path.join(root, "icon", "synopse_hc.png"), TARGET)
|
||||
save(normal, os.path.join(root, "icon", "synopse-256.png"), 256)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user