xml - Python Resize Multiple images ask user to continue -
i'm trying make script resize multiple or single image based on data pulled xml. question if have multiple images how can print out qusetion "there more 1 image wish resize image 2 also?... maybe " liek resize image 3 ?"
my script far follow,the problem taht resizez images @ start :
import os, glob import sys import xml.etree.celementtree et import re pil import image pathnow ='c:\\' items = [] textpath = [] imgpath = [] attribvalue = [] #append system argument list later use item in sys.argv: items.append(item) #change path directory newpath = pathnow + items[1] os.chdir(newpath) #end #get first agrument doc ref item in items: docxml = items[2] #search file file in glob.glob(docxml + ".xml"): tree = et.parse(file) rootfile = tree.getroot() rootchild in rootfile.iter('textelement'): if "svg" or "pdf" in rootchild.text: try: textpath = re.search('svg="(.+?)"', str(rootchild.text)).group(1) attribvalue.append(rootchild.get('elementid')) imgpath.append(textpath) except: continue image in imgpath: new_img_path = image[:-4] + '.png' new_image = image.open(new_img_path) new_size=int(sys.argv[3]), int(sys.argv[4]) try: new_image.thumbnail(new_size, image.antialias) new_image.save(new_img_path, 'png') except ioerror: print("cannot resize picture '%s'" % new_img_path) finally: new_image.close() print("done resizeing image: %s " % new_img_path) thank in advance.
zapo
change final loop to:
for idx, image in enumerate(imgpath): #img resizing goes here count_remaining = len(imgpath) - (idx+1) if count_remaining > 0: print("there {} images left resize.".format(count_remaining)) response = input("resize image #{}? (y/n)".format(idx+2)) #use `raw_input` in place of `input` python 2.7 , below if response.lower() != "y": break
Comments
Post a Comment