Skip to content

Instantly share code, notes, and snippets.

@make-github-pseudonymous-again
Last active June 29, 2016 17:21
Show Gist options
  • Save make-github-pseudonymous-again/f95d1229eabccb672be28086e980b5eb to your computer and use it in GitHub Desktop.
Save make-github-pseudonymous-again/f95d1229eabccb672be28086e980b5eb to your computer and use it in GitHub Desktop.
Sort images based on ratio for printing
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