Aug-12-2020, 07:27 PM
Hi there,
I'm trying to create a program whereby a user can resize images in their own, inputted directory. As you can see below, I am able to view their directory, but am unable to change the working directory of the program. What keeps happening is that the program creates a folder called 'path' in my own working directory, which is not what I want it to do.
This is the code in full so far:
Many thanks,
paulmerton4pope
I'm trying to create a program whereby a user can resize images in their own, inputted directory. As you can see below, I am able to view their directory, but am unable to change the working directory of the program. What keeps happening is that the program creates a folder called 'path' in my own working directory, which is not what I want it to do.
from PIL import Image import os import glob while True: dirname = input("Please enter/copy and paste the folder location of your images here > ") path = os.path.join(dirname,"**") oldpath = os.getcwd() print(oldpath) newpath = os.chdir('path') print(os.getcwd())I also need to ensure that, as users would be resizing images in bulk, that it doesn't come up with an error after creating the new sub-directory. In other words, to make sure that it doesn't try to create a sub-directory twice.
This is the code in full so far:
from PIL import Image import os import glob while True: dirname = input("Please enter/copy and paste the folder location of your images here > ") path = os.path.join(dirname,"**") oldpath = os.getcwd() print(oldpath) newpath = os.chdir('path') print(os.getcwd()) #newdir = os.makedirs('path/Thumbnails') math = input("What type of file are you working with? Please answer with file extension type - e.g. .jpg ") if math == ".jpg": for x in glob.glob(path, recursive=True): if x.endswith(".jpg"): print (path, x) xm = Image.open(x) new_height = int(input("Height of thumbnail in pixels?")) new_width = int(input("Width of thumbnail in pixels?")) new_size = xm.resize((new_width, new_height)) new_size.show() hapus = input("Are you happy with this image - yes or no? ") if hapus == "yes": print (path) if math == ".png": for y in glob.glob(path, recursive=True): if y.endswith(".png"): print (path, y) os.startfile(y) ym = Image.open(y) new_height = int(input("Height of thumbnail in pixels?")) new_width = int(input("Width of thumbnail in pixels?")) new_size = ym.resize((new_width, new_height)) new_size.show() #break #if hapus == "yes":As I say, I have come across a bit of a stumbling block with it and need to know what I've done wrong. If anyone can help, I would be very grateful.
Many thanks,
paulmerton4pope