Last active
August 29, 2015 14:22
-
-
Save veritech/fbcbf910a0f321e5ffce to your computer and use it in GitHub Desktop.
Make a vector xcimage set with a folder of PDF files
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
import os | |
import shutil | |
contentTemplate = """ | |
{ | |
"images" : [ | |
{ | |
"idiom" : "universal", | |
"filename" : "%s" | |
} | |
], | |
"info" : { | |
"version" : 1, | |
"author" : "xcode" | |
} | |
} | |
""" | |
def make_vector_imageset(imageName,path): | |
imageSetPath = '%s.imageset' % imageName.split('.')[0] | |
imageSetPath = os.path.join( | |
path, | |
imageSetPath | |
) | |
try: | |
os.mkdir(imageSetPath) | |
except OSError as e: | |
shutil.rmtree(imageSetPath) | |
os.mkdir(imageSetPath) | |
jsonPath = os.path.join( | |
imageSetPath, | |
'Contents.json' | |
) | |
fh = open( jsonPath,'w+') | |
fh.write( contentTemplate % imageName) | |
fh.close | |
imagePath = os.path.join( | |
path, | |
imageName | |
) | |
newImagePath = os.path.join( | |
imageSetPath, | |
imageName | |
) | |
print 'Existing %s -> %s' % (imagePath,newImagePath) | |
shutil.copy( imagePath, newImagePath) | |
if __name__ == '__main__': | |
path = 'nav icons' | |
for file in os.listdir(path): | |
if 'DS_Store' not in file and '.imageset' not in file: | |
print file | |
make_vector_imageset(file,path) | |
# break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment