Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ RUN apt-get update && apt-get install -y \
gir1.2-pango-1.0 \
libnginx-mod-http-fancyindex \
nginx-light \
optipng \
python3-gi-cairo \
python3-pil \
Copy link
Member

@TimidRobot TimidRobot Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove python3-pil WebP dependency (see comment on lines +208 to +219 for rationale)

tree \
&& rm -rf /var/lib/apt/lists/*
23 changes: 23 additions & 0 deletions scripts/genicons.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Standard library
from functools import reduce
from itertools import product
from PIL import Image
Copy link
Member

@TimidRobot TimidRobot Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove WebP related import (see comment on lines +208 to +219 for rationale)

import errno
import math
import os
Expand Down Expand Up @@ -135,6 +136,12 @@ def genicon(
show_chars(ctx, characters, foreground, padding, width, height)
return ctx

#function to create a Cairo canvas that write to a SVG file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a space after the hash and capitalize "function"

def create_svg_context(width, height, filepath):
surface = cairo.SVGSurface(filepath, width, height)
ctx = cairo.Context(surface)
return ctx


def main():
font_map = pangocairo.font_map_get_default()
Expand Down Expand Up @@ -195,6 +202,22 @@ def main():
# Will raise and exception on error
ctx.get_target().write_to_png(filepath)

# Optimize the just‐saved PNG with optipng (lossless compression)
os.system(f"optipng -o7 {filepath}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please quiet the output and set optimization level to 2:

os.system(f"optipng -o2 -quiet {filepath}")

File size comparison in bytes:

File prefix Prev o1 o2 o3 o5 o7
www/i/l/by-sa/000000/ff/ff/ff/76x22 1105 582 553 553 553 553
www/i/l/by-sa/000000/ff/ff/ff/88x31 17096 871 829 829 829 824

Script duration in seconds

Prev o1 o2 o3 o5 o7
14 132 179 240 434 1130


# Convert PNG -> WebP (smaller file size, quality=85)
img = Image.open(filepath)
webp_filepath = filepath.replace(".png", ".webp")
img.save(webp_filepath, format="webp", quality=85)

# Also render the same icon as SVG
svg_filepath = filepath.replace(".png", ".svg")
svg_ctx = create_svg_context(width, height, svg_filepath)
set_background(svg_ctx, background, width, height)
configure_font(svg_ctx, font_size)
show_chars(svg_ctx, chars, foreground, padding, width, height)
svg_ctx.show_page()
Comment on lines +208 to +219
Copy link
Member

@TimidRobot TimidRobot Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove WebP and SVG output. Both result in larger files than PNG.

File type size comparison in bytes:

File prefix PNG SVG scour WebP
www/i/l/by-sa/000000/ff/ff/ff/76x22 553 4471 2854 588
www/i/l/by-sa/000000/ff/ff/ff/88x31 829 4531 2813 858

The "scour" column represents SVGs updated using scour-project/scour: Scour - An SVG Optimizer / Cleaner



if __name__ == "__main__":
try:
Expand Down
Loading