Merge pull request #39 from kiwix/feature/macgills/no-flag-option

Allow no country code to be set
This commit is contained in:
Seán Mac Gillicuddy 2019-11-18 15:46:13 +00:00 committed by GitHub
commit c8d1a155a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu # vim: ai ts=4 sts=4 et sw=4 nu
''' Generate an Android ic_launcher friendly icon from a PNG logo """ Generate an Android ic_launcher friendly icon from a PNG logo
Requirements:
- imagemagick
- python3
Generated icon is a 512x512 piels wide 24b transparent PNG. Generated icon is a 512x512 piels wide 24b transparent PNG.
It contains a transparent background canvas (which can be It contains a transparent background canvas (which can be
@ -10,21 +14,22 @@
It then adds a resized version of the provided logo in the center It then adds a resized version of the provided logo in the center
Then adds two markers: Then adds two markers:
An offline marker indicating it's OFFLINE (bared WiFi icon) An offline marker indicating it's OFFLINE (bared WiFi icon)
A lang marker using a bubbled flag A lang marker using a bubbled flag (only added if version code supplied)
Script can be called with either a local PNG file or an URL to PNG. Script can be called with either a local PNG file or an URL to PNG.
The supported languages are based on the template flag-bubbles icons. ''' The supported languages are based on the template flag-bubbles icons. """
from __future__ import (unicode_literals, absolute_import, from __future__ import (unicode_literals, absolute_import,
division, print_function) division, print_function)
import logging import logging
import sys
import os import os
import re import re
import struct
import tempfile
import shutil import shutil
import struct
import sys
import tempfile
from io import StringIO from io import StringIO
from subprocess import call from subprocess import call
@ -141,8 +146,8 @@ def sq_resize(path, size, new_path=None):
return resize(path, size, size, new_path) return resize(path, size, size, new_path)
def main(logo_path, lang_code): def main(logo_path, lang_code=None):
if lang_code is not None:
if lang_code not in SUPPORTED_LANGS: if lang_code not in SUPPORTED_LANGS:
logger.error("No image template for language code `{}`.\n" logger.error("No image template for language code `{}`.\n"
"Please download a square PNG bubble flag for that lang " "Please download a square PNG bubble flag for that lang "
@ -205,6 +210,7 @@ def main(logo_path, lang_code):
x=OFFLINE_POSITION[0], y=OFFLINE_POSITION[1])) x=OFFLINE_POSITION[0], y=OFFLINE_POSITION[1]))
# multiply layer1p2 (white + logo + offline) with lang marker (layer3) # multiply layer1p2 (white + logo + offline) with lang marker (layer3)
if lang_code is not None:
layer2p3 = os.path.join(tmpd, 'layer2_layer3.png') layer2p3 = os.path.join(tmpd, 'layer2_layer3.png')
syscall('composite -geometry +{x}+{y} {l3} {l1p2} {l2p3}' syscall('composite -geometry +{x}+{y} {l3} {l1p2} {l2p3}'
.format(l3=layer3, l1p2=layer1p2, l2p3=layer2p3, .format(l3=layer3, l1p2=layer1p2, l2p3=layer2p3,
@ -213,6 +219,9 @@ def main(logo_path, lang_code):
# copy final result to current directory # copy final result to current directory
icon_path = os.path.join(CURRENT_PATH, icon_path = os.path.join(CURRENT_PATH,
'ic_launcher_512_{}.png'.format(lang_code)) 'ic_launcher_512_{}.png'.format(lang_code))
if lang_code is None:
shutil.copy(layer1p2, icon_path)
else:
shutil.copy(layer2p3, icon_path) shutil.copy(layer2p3, icon_path)
# remove temp directory # remove temp directory
@ -220,7 +229,4 @@ def main(logo_path, lang_code):
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usage:\t{} <logo_path> <lang-code>'.format(sys.argv[0]))
sys.exit(1)
main(*sys.argv[1:]) main(*sys.argv[1:])