Just a super rudimentary script that I made which hooks CairoSVG up to Pillow because apparently Firefox doesn't support SVG-formatted browserAction
images:
import cairosvg.surface
from PIL import Image
from io import BytesIO
import sys
def main(input=sys.stdin.buffer, output=sys.stdout.buffer):
svg2ico(url=input, write_to=output)
def svg2ico(*args, resolutions={96, 48, 32, 24, 16}, write_to=None, **kwargs):
t = cairosvg.surface.Tree(*args, **kwargs)
ims = []
for res in resolutions:
cairosvg.surface.PNGSurface(t, f:=BytesIO(), res * 2,
output_width=res, output_height=res).finish()
ims.append(Image.open(f))
im = ims.pop(0)
# Fix for Windows XP and MATE Desktop:
# add bitmap_format="bmp" to the following command
# - requires Pillow>=8.3.0
# - makes the resulting image files larger
# * https://github.com/python-pillow/Pillow/issues/2512
# * https://github.com/mate-desktop/eom/issues/310
im.save(f:=write_to or BytesIO(), format='ICO',
append_images=ims, sizes=[im.size for im in ims])
if not write_to:
return f.get_value()
if __name__ == '__main__':
sys.exit(main(*sys.argv[1:]))