File: makeicns.py

package info (click to toggle)
gajim 2.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,512 kB
  • sloc: python: 79,978; sh: 591; xml: 67; makefile: 6
file content (50 lines) | stat: -rwxr-xr-x 1,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import os
import shutil
from argparse import ArgumentParser
from subprocess import run

ICON_SVG = "gajim/data/icons/hicolor/scalable/apps/gajim.svg"


def create_icns(icon_path: str) -> None:
    tmpdir = "Gajim.iconset"
    if os.path.isdir(tmpdir):
        shutil.rmtree(tmpdir)
    os.mkdir(tmpdir)

    for size_pt in [16, 32, 128, 256, 512]:
        for scale in [1, 2]:
            size_px = scale * size_pt
            scale_txt = f"@{scale}" if scale != 1 else ""
            png_fn = f"icon_{size_pt}x{size_pt}{scale_txt}.png"
            png_path = os.path.join(tmpdir, png_fn)
            run(
                [
                    "inkscape",
                    "-z",
                    "-e",
                    png_path,
                    "-w",
                    str(size_px),
                    "-h",
                    str(size_px),
                    "-y",
                    "0",
                    ICON_SVG,
                ],
                check=True,
            )
    run(["iconutil", "-c", "icns", "-o", icon_path, tmpdir], check=True)

    shutil.rmtree(tmpdir)


if __name__ == "__main__":
    parser = ArgumentParser(
        description="Create a macOS .icns icon. Requires Inkscape and iconutil (macOS)."
    )
    parser.add_argument("output", help="bundle output location")
    args = parser.parse_args()

    create_icns(args.output)