from PIL import Image for i in range(142): if i == 0: tempName = 'Palm/template.png' else: j = i+1 tempName = 'Palm/template' + str(j) + '.png' im=Image.open(tempName) height,width = im.height,im.width print(height) im = im.resize((round(0.5*height),round(0.5*width))) im.save(tempName,"PNG")