Last active
June 29, 2016 17:21
-
-
Save make-github-pseudonymous-again/f95d1229eabccb672be28086e980b5eb to your computer and use it in GitHub Desktop.
Sort images based on ratio for printing
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
import os | |
import sys | |
import shutil | |
from PIL import Image | |
os.makedirs( '3_2' , exist_ok = True ) | |
os.makedirs( '4_3' , exist_ok = True ) | |
os.makedirs( 'unk' , exist_ok = True ) | |
for i , src in enumerate( sys.argv[1:] , 1 ) : | |
im = Image.open(src) | |
hi, lo = max(im.size), min(im.size) | |
ratio = hi / lo | |
x = int( round( ratio * 6 ) ) | |
basename = os.path.basename(src) | |
if x == 8 : | |
dst = '4_3/4_3_{i}_{basename}'.format( i = i , basename = basename ) | |
elif x == 9 : | |
dst = '3_2/3_2_{i}_{basename}'.format( i = i , basename = basename ) | |
else: | |
dst = 'unk/unk_{i}_{basename}'.format( i = i , basename = basename ) | |
print( 'copying {src} with ratio {ratio} to {dst}'.format( src=src,ratio=ratio,dst=dst)) | |
shutil.copy( src , dst ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment