Created
July 28, 2015 18:12
-
-
Save grennis/ff70561750378be2e7b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil | |
import os | |
import json | |
material_dir = os.path.expanduser('~/material-design-icons-2.0/') | |
ios_dir = '../MyProject-ios/MyProject/Images.xcassets/' | |
dest_dir = 'app/src/main/res/drawable-' | |
densities = ['xxxhdpi', 'xxhdpi', 'xhdpi', 'hdpi', 'mdpi'] | |
ios_res = {'1x': 'hdpi', '2x': 'xhdpi', '3x': 'xxhdpi'} | |
def copy_material_icon(group, name): | |
for d in range(0, len(densities) - 1): | |
ds = densities[d] | |
dd = densities[d + 1] | |
print (name) | |
shutil.copy(material_dir + group + '/drawable-' + ds + '/' + name + '_white_48dp.png', dest_dir + dd + '/' + name + '.png') | |
def copy_ios_image(dest_name, scale, src): | |
dest_name = dest_name.replace('-', '_').replace(' ', '_').lower() | |
dest = dest_dir + ios_res[scale] + '/' + dest_name + os.path.splitext(src)[1] | |
print dest_name + ' ' + scale | |
shutil.copy(src, dest) | |
def copy_ios_imageset(dest_name, dir): | |
with open(os.path.join(dir, 'Contents.json')) as data_file: | |
data = json.load(data_file) | |
for img in data['images']: | |
copy_ios_image(dest_name, img['scale'], os.path.join(dir, img['filename'])) | |
def copy_ios_images(imgset): | |
for name in os.listdir(ios_dir + imgset): | |
dir = os.path.join(ios_dir + imgset, name) | |
if os.path.isdir(dir): | |
copy_ios_imageset(name.replace('.imageset',''), dir) | |
copy_material_icon('social', 'ic_share') | |
copy_material_icon('communication', 'ic_email') | |
copy_material_icon('communication', 'ic_call') | |
copy_material_icon('file', 'ic_file_upload') | |
copy_material_icon('file', 'ic_cloud_upload') | |
copy_material_icon('editor', 'ic_mode_edit') | |
copy_ios_images('Image Name') | |
copy_ios_images('Another Image Name') | |
copy_ios_images('Yet Another') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment