Created
January 30, 2018 09:12
-
-
Save j796160836/705272ce79bb41258e5c77ecdb46a2aa to your computer and use it in GitHub Desktop.
Copy illustrator CC output images to your Android project.
This file contains 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
#!/usr/bin/env python | |
# encoding: utf-8 | |
# ## copyToProject.py | |
# Copy illustrator CC output images to your Android project. | |
# ### How to use: | |
# 1. Put this script at the illustrator CC output folder | |
# 2. Edit `projectPath` and `targetPrefix` for your want | |
# For example, we have these files: | |
# ``` | |
# ./ic_launcherhdpi.png | |
# ./ic_launcherldpi.png | |
# ./ic_launchermdpi.png | |
# ./ic_launcherxhdpi.png | |
# ./ic_launcherxxhdpi.png | |
# ./ic_launcherxxxhdpi.png | |
# ``` | |
# Copy into | |
# ``` | |
# ./AndroidStudioProjects/app/src/main/res/drawable-hdpi/ic_launcher.png | |
# ./AndroidStudioProjects/app/src/main/res/drawable-ldpi/ic_launcher.png | |
# ./AndroidStudioProjects/app/src/main/res/drawable-mdpi/ic_launcher.png | |
# ./AndroidStudioProjects/app/src/main/res/drawable-xhdpi/ic_launcher.png | |
# ./AndroidStudioProjects/app/src/main/res/drawable-xxhdpi/ic_launcher.png | |
# ./AndroidStudioProjects/app/src/main/res/drawable-xxxhdpi/ic_launcher.png | |
# ``` | |
import os | |
projectPath='./AndroidStudioProjects/MyProject/app/src/main/res/' | |
targetPrefix='drawable' # Choose mipmap or drawable | |
postfixes=['hdpi', 'ldpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi'] | |
# Create sub-folder at project path | |
for postfix in postfixes: | |
directory=projectPath+targetPrefix+'-'+postfix | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
# Find files need to copy | |
files=[] | |
for f in os.listdir("."): | |
if f.endswith('mdpi.png'): | |
files.append(f.replace('mdpi.png', '')) | |
print(files) | |
# Copy into project | |
for pic in files: | |
for postfix in postfixes: | |
if os.path.exists(pic+postfix+'.png'): | |
os.rename(pic+postfix+'.png', projectPath+targetPrefix+'-'+postfix+'/'+pic.replace('-', '_')+'.png') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment