-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_frameScreenshots.py
executable file
·128 lines (102 loc) · 4.85 KB
/
02_frameScreenshots.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/python
import os
import subprocess
import platform
from pathlib import Path
import json
langs_and_fonts = {
'ca': 'Sarabun-Bold',
'de-DE': 'Sarabun-Bold',
'en-US': 'Sarabun-Bold',
'fr-FR': 'Sarabun-Bold',
'he-IL': 'Arimo-Bold',
'nl-NL': 'Sarabun-Bold',
'it-IT': 'Sarabun-Bold',
'es-ES': 'Sarabun-Bold'
}
def generate_text(text, font):
print(" " + text.replace("\n", "\\n"))
os.system(
"convert -size 1698x750 xc:none -gravity Center -pointsize 130 -fill '#167df0' -font "
+ font
+ ' -annotate 0 "'
+ text
+ '" /tmp/text.png')
def generate_tablet_text(text, font):
print(" " + text.replace("\n", "\\n"))
os.system(
"convert -size 1730x350 xc:none -gravity Center -pointsize 80 -fill '#167df0' -font "
+ font
+ ' -annotate 0 "'
+ text
+ '" /tmp/text.png')
def simple_phone(text, background_file, screenshotFile, outputFile, font):
generate_text(text, font)
os.system('convert templates/' + background_file
+ ' templates/phone.png -geometry +0+0 -composite '
+ screenshotFile + ' -geometry +306+992 -composite '
+ '/tmp/text.png -geometry +0+0 -composite '
+ outputFile)
def simple_tablet(text, screenshot_file, output_file, font):
generate_tablet_text(text, font)
os.system('convert ' + screenshot_file + ' -resize 1285 "/tmp/resized-image.png"')
os.system('convert templates/tablet.png '
+ '/tmp/resized-image.png -geometry +224+459 -composite '
+ '/tmp/text.png -geometry +0+0 -composite '
+ output_file)
def two_phones(text, raw_screenshots_path, output_file, font):
generate_text(text, font)
os.system('convert templates/background2.png '
+ 'templates/twophones-a.png -geometry +0+10 -composite '
+ raw_screenshots_path + '/03a.png -geometry +119+992 -composite '
+ 'templates/twophones-b.png -geometry +0+0 -composite '
+ raw_screenshots_path + '/03b.png -geometry +479+1540 -composite '
+ '/tmp/text.png -geometry +0+0 -composite '
+ output_file)
def generate_screenshots(language, font):
print(language)
with open('strings/' + language + '.json') as textDefinitions:
texts = json.load(textDefinitions)
raw_screenshots_path = 'raw/' + language
output_path = '../listings/' + language + "/graphics"
Path(output_path + '/phone-screenshots').mkdir(parents=True, exist_ok=True)
Path(output_path + '/large-tablet-screenshots').mkdir(parents=True, exist_ok=True)
if not Path(raw_screenshots_path + '/00.png').is_file():
raw_screenshots_path = 'raw/en-US'
simple_phone(texts["00.png"], 'background1.png', raw_screenshots_path + '/00.png', output_path + '/phone-screenshots/00.png', font)
two_phones(texts["01.png"], raw_screenshots_path, output_path + '/phone-screenshots/01.png', font)
simple_phone(texts["02.png"], 'background1.png', raw_screenshots_path + '/01.png', output_path + '/phone-screenshots/02.png', font)
simple_phone(texts["03.png"], 'background2.png', raw_screenshots_path + '/02.png', output_path + '/phone-screenshots/03.png', font)
simple_phone(texts["04.png"], 'background1.png', raw_screenshots_path + '/04.png', output_path + '/phone-screenshots/04.png', font)
simple_phone(texts["05.png"], 'background2.png', raw_screenshots_path + '/05.png', output_path + '/phone-screenshots/05.png', font)
if not Path(raw_screenshots_path + '/tablet.png').is_file():
raw_screenshots_path = 'raw/en-US'
simple_tablet(texts["tablet.png"], raw_screenshots_path + '/tablet.png', output_path + '/large-tablet-screenshots/tablet.png', font)
os.system('mogrify -resize 1120 "' + output_path + '/phone-screenshots/0*.png"')
os.system('mogrify -resize 1120 "' + output_path + '/large-tablet-screenshots/tablet.png"')
def check_os():
"""Currently only working on Linux."""
return platform.system() == 'Linux' or platform.system() == 'Darwin'
def check_packages():
"""ImageMagicks convert and morgify are required."""
common = b'Version: ImageMagick'
try:
return common in subprocess.check_output(['convert', '-version']) and common in subprocess.check_output(
['mogrify', '-version'])
except subprocess.CalledProcessError:
return False
def check_fonts():
"""Check if required fonts are installed."""
try:
for font in langs_and_fonts.values():
if bytes(font.encode()) not in subprocess.check_output(['fc-list', '-v']):
return False
except subprocess.CalledProcessError:
return False
return True
if __name__ == '__main__':
assert (check_os())
assert (check_packages())
assert (check_fonts())
for lang, font in langs_and_fonts.items():
generate_screenshots(lang, font)