from sys import argv import Image import ImageFilter quality = 80 width = 125 heigth = 125 source = False thumb = False sharp = False if '-q' in argv : quality = int ( argv [ argv . index ( '-q' ) + 1 ]) if '-h' in argv : heigth = int ( argv [ argv . index ( '-h' ) + 1 ]) if '-w' in argv : width = int ( argv [ argv . index ( '-w' ) + 1 ]) if '-i' in argv : source = argv [ argv . index ( '-i' ) + 1 ] if '-o' in argv : thumb = argv [ argv . index ( '-o' ) + 1 ] if '-s' in argv : sharp = True if source and thumb : im = Image . open ( source ) im . thumbnail (( width , heigth ), Image . ANTIALIAS ) if sharp : im . filter ( ImageFilter . SHARPEN ) im . save ( thumb , "JPEG" , quality = quality )