-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-images.py
executable file
·50 lines (43 loc) · 1.39 KB
/
generate-images.py
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 json
import pprint
import subprocess
import collections
from ruamel.yaml import YAML
FORMATS = [ '.jpg', '.jpeg', '.png' ]
PATH_THUMB = 'img/thumbs'
PATH_CONFIG = '/etc/lightdm/web-greeter.yml'
SIZE = '100x56'
yaml = YAML(typ="rt")
paths = [ 'img/wallpapers' ]
def get_config(fpath):
"""Read yaml from file"""
with open(fpath) as f:
try:
return yaml.load(f)
except Exception as e:
print(f"Warning: could not parse yaml file: {fpath}")
print(f"Exception: {e}")
return None
config = get_config(PATH_CONFIG)
if config and 'branding' in config and 'background_images_dir' in config['branding']:
path = config['branding']['background_images_dir']
if path:
paths.append(path)
scriptpath = os.path.realpath(__file__)
dirpath = os.path.dirname(scriptpath)
abspath = os.path.abspath(dirpath)
os.chdir(abspath)
for path in paths:
for root, directories, filenames in os.walk(path):
for filename in filenames:
filepath = os.path.join(root, filename)
name, ext = os.path.splitext(filename)
if ext in FORMATS:
subprocess.call(['gm', 'convert',
'-size', SIZE,
filepath,
'-resize', SIZE,
'+profile', '*',
'/'.join([PATH_THUMB, filename])])