88 lines
2.8 KiB
Python
88 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Genera le icone dell'app in stile Sailfish OS:
|
|
sfondo a gradiente azzurro->blu con angoli molto arrotondati,
|
|
libro aperto bianco con ombra morbida e righe di testo tenui.
|
|
Dimensioni: 86, 108, 128, 172 (struttura standard hicolor)."""
|
|
import os
|
|
from PIL import Image, ImageDraw
|
|
|
|
# gradiente Sailfish: azzurro chiaro (alto) -> blu profondo (basso)
|
|
C_TOP = (94, 210, 240) # #5ED2F0
|
|
C_BOT = (14, 111, 168) # #0E6FA8
|
|
PAGE = (255, 255, 255)
|
|
TEXT = (120, 190, 225) # righe del testo, tenue
|
|
SPINE = (200, 225, 240)
|
|
|
|
|
|
def gradient(size, c1, c2):
|
|
img = Image.new("RGB", (size, size))
|
|
d = ImageDraw.Draw(img)
|
|
for y in range(size):
|
|
t = y / (size - 1)
|
|
d.line([(0, y), (size, y)],
|
|
fill=(int(c1[0] + (c2[0] - c1[0]) * t),
|
|
int(c1[1] + (c2[1] - c1[1]) * t),
|
|
int(c1[2] + (c2[2] - c1[2]) * t)))
|
|
return img
|
|
|
|
|
|
def draw_icon(size):
|
|
m = size * 0.05
|
|
r = size * 0.22
|
|
out = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
|
|
|
# sfondo: gradiente ritagliato nel rounded rect
|
|
grad = gradient(size, C_TOP, C_BOT).convert("RGBA")
|
|
mask = Image.new("L", (size, size), 0)
|
|
ImageDraw.Draw(mask).rounded_rectangle([m, m, size - m, size - m],
|
|
radius=r, fill=255)
|
|
out.paste(grad, (0, 0), mask)
|
|
|
|
d = ImageDraw.Draw(out)
|
|
|
|
cx = size / 2
|
|
top = size * 0.33
|
|
bot = size * 0.66
|
|
half = size * 0.15
|
|
ol = size * 0.24
|
|
orr = size * 0.76
|
|
|
|
def pages():
|
|
return ([(cx - half, top), (cx, top), (cx, bot), (ol, bot + size * 0.035)],
|
|
[(cx, top), (cx + half, top), (orr, bot + size * 0.035), (cx, bot)])
|
|
|
|
lp, rp = pages()
|
|
# ombra morbida sotto il libro (rilievo stile Sailfish)
|
|
sh = size * 0.022
|
|
shadow = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
|
ds = ImageDraw.Draw(shadow)
|
|
lps, rps = pages()
|
|
ds.polygon([(x, y + sh) for x, y in lps], fill=(0, 60, 100, 90))
|
|
ds.polygon([(x, y + sh) for x, y in rps], fill=(0, 60, 100, 90))
|
|
out.alpha_composite(shadow)
|
|
|
|
d.polygon(lp, fill=PAGE)
|
|
d.polygon(rp, fill=PAGE)
|
|
d.rectangle([cx - size * 0.016, top, cx + size * 0.016, bot], fill=SPINE)
|
|
|
|
# righe di testo sulle pagine
|
|
lw = max(1, int(size * 0.012))
|
|
for yf, dy in ((0.46, 0.022), (0.53, 0.026), (0.60, 0.030)):
|
|
y = size * yf
|
|
d.line([(cx - half + size * 0.045, y), (ol + size * 0.05, y + size * dy)],
|
|
fill=TEXT, width=lw)
|
|
d.line([(cx + half - size * 0.045, y), (orr - size * 0.05, y + size * dy)],
|
|
fill=TEXT, width=lw)
|
|
return out
|
|
|
|
|
|
def main():
|
|
for s in (86, 108, 128, 172):
|
|
os.makedirs(f"icons/{s}x{s}", exist_ok=True)
|
|
draw_icon(s).save(f"icons/{s}x{s}/harbour-calibreweb.png")
|
|
print("icone scritte: 86, 108, 128, 172")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|