Created
December 7, 2012 18:58
-
-
Save jarodl/4235526 to your computer and use it in GitHub Desktop.
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
""" | |
List all retina assets (@2x) that have odd dimensions. | |
------------------------------------------------------ | |
""" | |
import os | |
from re import search | |
from PIL import Image | |
from argparse import ArgumentParser | |
def all_retina_file_paths(directory): | |
retina_file_paths = [] | |
for (dirpath, dirnames, filenames) in os.walk(directory): | |
for filename in filenames: | |
if search('(@2x)', filename): | |
fullpath = dirpath + '/' + filename | |
retina_file_paths.append(fullpath) | |
return retina_file_paths | |
def group_images_by_odd_and_even(image_paths): | |
odd_image_paths = [] | |
even_image_paths = [] | |
for image_path in image_paths: | |
try: | |
image = Image.open(image_path) | |
except IOError: | |
print 'Not a valid image: ' + image_path | |
is_even_size = True in set(map(lambda s: s % 2 == 0, image.size)) | |
if is_even_size: | |
even_image_paths.append(image_path) | |
else: | |
odd_image_paths.append(image_path) | |
return odd_image_paths, even_image_paths | |
def main(): | |
parser = ArgumentParser(description='List retina assets with an odd size') | |
parser.add_argument('directory', metavar='D', type=str, nargs=1, | |
help='A directory to look for retina assets') | |
args = parser.parse_args() | |
directory = args.directory[0] | |
retina_paths = all_retina_file_paths(directory) | |
odd_images, even_images = group_images_by_odd_and_even(retina_paths) | |
print '\nSummary' | |
print '-' * 20 | |
for odd_image in odd_images: | |
print odd_image | |
print '' | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment