oxjs/tools/geo/py/png.py

46 lines
1.7 KiB
Python
Raw Permalink Normal View History

2011-11-23 14:53:17 +00:00
import Image
import json
import os
2011-11-24 18:38:10 +00:00
import sys
2011-11-23 14:53:17 +00:00
svg_path = '../svg/icons/'
png_path = '../png/icons/4096/'
for file in os.listdir(svg_path):
svg_file = svg_path + file
print svg_file
if svg_file[-4:] == '.svg' and not os.path.islink(svg_file):
tmp_file = png_path + file + '.png'
png_file = tmp_file.replace('.svg.png', '.png')
2012-03-27 15:28:51 +00:00
if True: #not os.path.exists(png_file):
2011-11-23 14:53:17 +00:00
os.system('qlmanage -t -s 4096 -o ' + png_path + ' ' + svg_file)
while not os.path.exists(tmp_file):
pass
os.rename(tmp_file, png_file)
image = Image.open(png_file)
for size in [1024, 256, 64, 16]:
image = image.resize((size, size), Image.ANTIALIAS)
image.save(png_file.replace('/4096/', '/%d/' % size))
2011-11-30 14:28:01 +00:00
if sys.argv[-1] != '-nopng':
2011-11-24 18:38:10 +00:00
for file in os.listdir('../png/flags/'):
if file[-4:] == '.png':
country = file[:-4]
png_file = png_path + country + '.png'
print png_file
image = Image.open(png_file)
# include 4096 to overwrite manually generated image
for size in [4096, 1024, 256, 64, 16]:
2011-11-30 14:28:01 +00:00
if size < 4096:
image = image.resize((size, size), Image.ANTIALIAS)
2011-11-24 18:38:10 +00:00
image.save(png_file.replace('/4096/', '/%d/' % size))
2011-11-23 14:53:17 +00:00
2011-11-30 14:28:01 +00:00
image = Image.new('RGB', (1216, 1216))
2011-11-23 14:53:17 +00:00
f = open('../json/countries.json')
countries = json.loads(f.read())
f.close()
for i, country in enumerate(countries):
file = png_path.replace('/4096/', '/64/') + country['code'] + '.png'
if os.path.exists(file):
2011-11-30 14:28:01 +00:00
image.paste(Image.open(file), (i % 19 * 64, int(i / 19) * 64))
2011-11-23 14:53:17 +00:00
image.save('../png/icons.png')