Answer the question
In order to leave comments, you need to log in
How to truncate the path so that only the filename remains?
In general, I made a png to jpg image converter (and others), in the tkinter window I choose which method and the file selection window opens in the explorer and this is written to the filename variable and I need to somehow trim the path leaving only the file name (because the path is different each time) so that ""im = Image.open(file)"" does not throw an error. I tried everything I could, but alas. A snippet of code if necessary (without trimming options).
filename = askopenfilename()
for file in filename:
im = Image.open(file)
rgb_im = im.convert('RGB')
rgb_im.save(file.replace("jpg", "png"), quality=95)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question