Skip to content

Instantly share code, notes, and snippets.

@gelosi
Created December 16, 2016 12:33
Show Gist options
  • Save gelosi/58fe54469330a46ccc652042ed20a27c to your computer and use it in GitHub Desktop.
Save gelosi/58fe54469330a46ccc652042ed20a27c to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import argparse
import os
parser = argparse.ArgumentParser(description='Process input icon and output a set of icons with given sizes')
parser.add_argument('file', metavar = 'F', type=str, default="icon.png", help='file to look for')
parser.add_argument('--sizes', type=float, nargs='+', default=[20, 29, 40, 60, 76, 83.5], help='sizes for processing')
#pass me as parameter to parse_args if any :)
testArgs = ["urbi_icon_fluo.test.dot.png", "--sizes", "1", "2", "3"]
args = parser.parse_args()
print("OKI")
print("sizes: {sizes}".format(sizes = args.sizes))
print("file : {file}".format(file = args.file))
outFile = args.file.split(".")
fileName = ".".join(outFile[:-1])
fileExt = outFile[-1]
print "file: {0} ext: {1}".format(fileName, fileExt)
for size in args.sizes:
for scale in [1,2,3]:
formatArgs = {
'size':size,
'resize':size * scale,
'scale':scale,
'inputFile':args.file,
'fileName':fileName,
'fileExt':fileExt
}
cmd = "convert {inputFile} -resize {resize}x{resize} {fileName}{size}@{scale}x.{fileExt}".format(**formatArgs)
print(cmd)
os.system(cmd)
@gelosi
Copy link
Author

gelosi commented Dec 16, 2016

it's probably too straightforward, and later makes sense to copypaste some image.xcassets generation. might be nice together

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment