Skip to content

Instantly share code, notes, and snippets.

@veritech
Last active August 29, 2015 14:22
Show Gist options
  • Save veritech/fbcbf910a0f321e5ffce to your computer and use it in GitHub Desktop.
Save veritech/fbcbf910a0f321e5ffce to your computer and use it in GitHub Desktop.
Make a vector xcimage set with a folder of PDF files
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