import os, sys import Image for infile in sys.argv[1:]: try: converted = 0 if os.path.splitext(infile)[1] != ".jpg": os.popen ("convert "+infile+" "+os.path.splitext(infile)[0]+".jpg") infile1 = os.path.splitext(infile)[0]+".jpg" converted = 1 else: infile1 = infile im = Image.open(infile1) biggest = im.histogram()[0] zero = 0 nonzero = 0 critical = 0 ratio = 0 for i in im.histogram(): if biggest < i: biggest = i step = int(biggest/3) for i in im.histogram(): if float(i)/float(biggest) < 0.001: zero = zero+1 else: nonzero = nonzero+1 if i >= step: critical = critical+1 nonzero = nonzero + 1 zero = zero + 1 ratio = nonzero / zero if critical < 14 and zero > 5 and ratio < 8: print "----- SPAM!" else: print "----- NOT SPAM!" # print critical,"\t",zero,"\t",nonzero,"\t",ratio # print infile if converted == 1: os.popen("rm "+infile1) converted = 0 except IOError: print "error", infile