Created
March 11, 2013 17:02
-
-
Save yejianye/5135725 to your computer and use it in GitHub Desktop.
generate ios assets from retina version ([email protected] -> image.png)
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
#!/usr/bin/env python | |
from PIL import Image | |
from argh import arg, dispatch_command | |
import os | |
def gen_assets(rootdir, force=False): | |
for root, dirs, files in os.walk(rootdir): | |
for d in dirs: | |
gen_thumb(os.path.join(root, d), force=force) | |
for f in files: | |
if f.endswith('@2x.png') and not f.endswith('[email protected]'): | |
f = os.path.relpath(os.path.join(root, f)) | |
name = f.replace('@2x.png', '.png') | |
if os.path.exists(name) and not force: | |
continue | |
print '%s -> %s' % (f, name) | |
img = Image.open(f) | |
width, height = img.size | |
img.thumbnail((width/2, height/2), Image.ANTIALIAS) | |
img.save(name, "PNG") | |
@dispatch_command | |
@arg('ROOTDIR', default='.', help='Root directory for searching assets') | |
@arg('--force', '-f', default=False, help='Force generating assets. Will overwrite existing files.') | |
def main(args): | |
gen_assets(args.ROOTDIR, force=args.force) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment