Debian Codegraph @

icons/make_ico_files.py

raw
1 #!/usr/bin/env python
2
3
4 __license__ = 'GPL v3'
5 __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
6
7 import os
8 import shutil
9 import subprocess
10 import sys
11
12 d, j, a = (getattr(os.path, x) for x in ('dirname', 'join', 'abspath'))
13 base = d(a(__file__))
14 os.chdir(base)
15
16 imgsrc = j(d(base), 'imgsrc')
17 sources = {'library': j(imgsrc, 'calibre.svg'), 'ebook-edit': j(imgsrc, 'tweak.svg'), 'viewer': j(imgsrc, 'viewer.svg'), 'favicon': j(imgsrc, 'calibre.svg')}
18 if sys.argv[-1] == 'only-logo':
19 sources = {'library': sources['library']}
20
21 for name, src in sources.items():
22 os.mkdir('ico_temp')
23 try:
24 names = []
25 for sz in (16, 24, 32, 48, 64, 256):
26 iname = os.path.join('ico_temp', f'{sz}x{sz}.png')
27 subprocess.check_call(['rsvg-convert', src, '-w', str(sz), '-h', str(sz), '-o', iname])
28 subprocess.check_call(['optipng', '-o7', '-strip', 'all', iname])
29 if sz >= 128:
30 names.append('-r') # store as raw PNG to reduce size
31 else:
32 names.extend(['-t', '0']) # see https://bugzilla.gnome.org/show_bug.cgi?id=755200
33 names.append(iname)
34 subprocess.check_call(['icotool', '-c', '--output=' + name + '.ico'] + names)
35 finally:
36 shutil.rmtree('ico_temp')