1
1
#!/usr/bin/python3
2
- # Copyright © 2018, 2019, 2020, 2022, 2024 Tom Most <[email protected] >
2
+ # Copyright © 2018, 2019, 2020, 2022, 2024, 2025 Tom Most <[email protected] >
3
3
#
4
4
# This program is free software: you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
55
55
from typing import Optional , Sequence
56
56
57
57
import brotli
58
+ import oxipng
58
59
import tinycss2
59
60
import zopfli .gzip
60
61
@@ -220,7 +221,7 @@ async def rasterize_favicon(favicon: Path, build_dir: Path, w: Writer) -> None:
220
221
"""
221
222
Use Inkscape to generate two raster versions of the favicon:
222
223
223
- - icon-[hexchars].png — a 152x152 PNG, optimized with optipng .
224
+ - icon-[hexchars].png — a 152x152 PNG, optimized with oxipng .
224
225
- icon-[hexchars].ico — ICO with 16x16, 24x24, 32x32, and 64x64 versions.
225
226
Built with icotool.
226
227
"""
@@ -240,13 +241,19 @@ async def rasterize_favicon(favicon: Path, build_dir: Path, w: Writer) -> None:
240
241
raise ProcFailed (f"inkscape failed to write { outfile !r} " , stdout , stderr )
241
242
242
243
png_path = Path (outfiles .pop ())
243
- ico_path = build_dir / f"{ favicon .stem } .ico"
244
- await asyncio .gather (
245
- _run (["optipng" , "-quiet" , str (png_path )]),
246
- _run (["icotool" , "--create" , "-o" , str (ico_path ), * outfiles ]),
244
+ oxipng .optimize (
245
+ str (png_path ),
246
+ level = 4 ,
247
+ interlace = oxipng .Interlacing .Off ,
248
+ strip = oxipng .StripChunks .safe (),
249
+ deflate = oxipng .Deflaters .zopfli (15 ),
250
+ optimize_alpha = True ,
247
251
)
248
-
249
252
w .add_file (hashname ("icon" , "png" , png_path .read_bytes ()), png_path )
253
+
254
+ ico_path = build_dir / f"{ favicon .stem } .ico"
255
+ # icotool reencodes the PNGs with libpng, so there's no point optimizing them.
256
+ await _run (["icotool" , "--create" , "-o" , str (ico_path ), * outfiles ])
250
257
w .add_file (hashname ("icon" , "ico" , ico_path .read_bytes ()), ico_path )
251
258
252
259
0 commit comments