'''ReduceAll.py Reduce all .JPG images in the specified folder by a factor of SCALE. Normally SCALE = 0.25 ''' SCALE = 0.25 SFACTOR = 1.0/SCALE def list_JPGs(folder): import os files = os.listdir(folder) return filter(lambda f: f[-4:]==".JPG", files) image_files = list_JPGs("Still-Life") def reduce_image(folder, filename): print "Preparing to reduce the image: "+folder+"/"+filename pmOpenImage(1, folder+"/"+filename) width = pmGetImageWidth(1) height = pmGetImageHeight(1) w1 = int(SCALE*width) h1 = int(SCALE*height) pmSetSource1(1) newWin = pmNewImage(2, "Reduced version of "+filename, w1, h1, 255, 0, 0) pmSetDestination(newWin) pmSetFormula("S1("+str(SFACTOR)+"*x,"+str(SFACTOR)+"*y)") pmCompute() pmSaveImageAs(newWin, folder+"/Reduced-"+filename) for fn in image_files: reduce_image("Still-Life", fn)