import Imageimport sys, osimport stringerrorOut = sys.stderrerrorOutput = open('imgresize.log', 'w')sys.stderr = errorOutputdef resizeImg(imgFile): print("PY - resizeImg - " + imgFile) myLen = len(imgFile) myExt = string.lower(imgFile[myLen - 4:myLen]) if (myExt != ".jpg"): print ("Bad extension: " + myExt) return img1 = Image.open(imgFile) img1Size = img1.size if img1Size[0] > 3000: sizeMod = 0.25 elif img1Size[0] > 2000: sizeMod = 0.35 elif img1Size[0] > 1000: sizeMod = 0.5 else: print "File " + imgFile + "Already at size X: " + str(img1Size[0]) + " Y: " + str(img1Size[1]) return sizex = img1Size[0] * sizeMod sizey = img1Size[1] * sizeMod print "Changing file: " + imgFile + " from X: " + str(img1Size[0])+ " Y: " + str(img1Size[1]) + "To X: " + str(sizex) + " Y: " + str(sizey) img2 = img1.resize((int(sizex), int(sizey)), Image.ANTIALIAS) img2.save(imgFile) print("PY - resizeImgSuccess")def main(): for root, dirs, files in os.walk("./"): for file in files: currentFile = os.path.join(root, file) if (os.path.isfile(currentFile)): resizeImg(currentFile) else: print "Does Not Exist: " + currentFile main()