Welcome to mirror list, hosted at ThFree Co, Russian Federation.

makeicns.py « mac - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 562b6bd34365eb1128e6ef26c812641e058c3352 (plain)
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
#!/usr/bin/env python3
import os
import shutil
from argparse import ArgumentParser
from subprocess import run

ICON_SVG = 'gajim/data/icons/hicolor/scalable/apps/org.gajim.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)