Created
March 22, 2012 01:13
-
-
Save milesegan/2154962 to your computer and use it in GitHub Desktop.
python retina display resources helper script
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 | |
# | |
# Simple script that uses PIL to automatically generate both 1x and 2x resolution | |
# PNGs from a source directory of 2x files. Handy for iPhone/iPad retina assets. | |
# | |
import glob | |
import os.path | |
import PIL.Image | |
import shutil | |
import sys | |
def main(): | |
if len(sys.argv) != 3: | |
print "usage: make_resources sourcedir destdir" | |
sys.exit(1) | |
srcdir = sys.argv[1] | |
dstdir = sys.argv[2] | |
files = glob.glob(os.path.join(srcdir, "*.png")) | |
for filename in files: | |
base = os.path.splitext(os.path.basename(filename))[0] | |
dstpath2x = os.path.join(dstdir, base + "@2x.png") | |
shutil.copyfile(filename, dstpath2x) | |
img = PIL.Image.open(filename) | |
dstpath1x = os.path.join(dstdir, base + ".png") | |
newsize = [x / 2 for x in img.size] | |
smallimg = img.resize(newsize) | |
smallimg.save(dstpath1x) | |
print "%s -> %s, %s" % (filename, dstpath1x, dstpath2x) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment