mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Script to render icons
This commit is contained in:
parent
4f4ab5af27
commit
8b55311323
@ -4,14 +4,14 @@
|
||||
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
import os
|
||||
import os, glob, subprocess, argparse
|
||||
|
||||
duplicates = {
|
||||
'character-set': ['languages'],
|
||||
'calibre': ['library', 'lt'],
|
||||
'format-text-color': 'lookfeel',
|
||||
'format-text-color': ['lookfeel'],
|
||||
'books_in_series': ['series'],
|
||||
'plugins.svg': ['plugins/plugin_upgrade_ok.svg'],
|
||||
'plugins.svg': ['plugins/plugin_upgrade_ok'],
|
||||
}
|
||||
|
||||
sizes = {
|
||||
@ -23,13 +23,45 @@ sizes = {
|
||||
|
||||
skip = {'calibre'}
|
||||
|
||||
j = os.path.join
|
||||
base = os.path.dirname(os.path.abspath(__file__))
|
||||
output_base = j(os.path.dirname(base), 'resources', 'images')
|
||||
|
||||
for src in os.listdir(base):
|
||||
if src.endswith('.svg'):
|
||||
name = src.rpartition('.')[0]
|
||||
names = [name] + duplicates.get(name, [])
|
||||
for oname in names:
|
||||
if oname in skip:
|
||||
|
||||
def iterfiles(only=()):
|
||||
for src in glob.glob(j(base, '*.svg')) + glob.glob(j(base, 'plugins/*.svg')):
|
||||
name = os.path.relpath(src, base).rpartition('.')[0]
|
||||
if only and name not in only:
|
||||
continue
|
||||
src = os.path.join(base, name + '.svg')
|
||||
output_names = [n for n in [name] + duplicates.get(name, []) if n not in skip]
|
||||
output_files = [j(output_base, n) + '.png' for n in output_names]
|
||||
if output_files:
|
||||
yield src, output_files
|
||||
|
||||
|
||||
def rsvg(src, size, dest):
|
||||
cmd = ['rsvg-convert', '-d', '96', '-p', '96']
|
||||
if size != 'original':
|
||||
cmd += ['--width', size, '--height', size]
|
||||
subprocess.check_call(cmd + ['-o', dest, src])
|
||||
subprocess.check_call(['optipng', '-o7', '-quiet', '-strip', 'all', dest])
|
||||
|
||||
|
||||
def render(src, output_files):
|
||||
for dest in output_files:
|
||||
oname = os.path.basename(dest).rpartition('.')[0]
|
||||
size = sizes.get(oname, '128')
|
||||
print('Rendering', oname, 'at size:', size)
|
||||
rsvg(src, size, dest)
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('only', nargs='*', default=[], help='Only render the specified icons')
|
||||
args = p.parse_args()
|
||||
for src, ofiles in iterfiles(args.only):
|
||||
render(src, ofiles)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -74,15 +74,7 @@ def get_path(path, data=False, allow_user_override=True):
|
||||
return f.read()
|
||||
return fpath
|
||||
|
||||
if os.environ.get('CALIBRE_TEST_ICONS') == '1' and os.path.exists('/home/kovid/work/calibre/imgsrc/new'):
|
||||
def get_image_path(path, data=False, allow_user_override=True):
|
||||
if not path:
|
||||
return get_path('images', allow_user_override=allow_user_override)
|
||||
q = '/home/kovid/work/calibre/imgsrc/new/' + path[:-4] + '.svg'
|
||||
if os.path.exists(q):
|
||||
return q
|
||||
return get_path('images/'+path, data=data, allow_user_override=allow_user_override)
|
||||
else:
|
||||
|
||||
def get_image_path(path, data=False, allow_user_override=True):
|
||||
if not path:
|
||||
return get_path('images', allow_user_override=allow_user_override)
|
||||
|
Loading…
x
Reference in New Issue
Block a user