1

I am trying to resize an image:

    from tkinter import filedialog
                        path = filedialog.askopenfilename(initialdir="C:\\Users\\josho\\Pictures", title="Choose a photo for your profile.", filetypes=(("png files", "*.png"),("jpg files", "*.jpg"), ("gif files", "*.gif")))
                        print(path)
                        limage = Image.open(path)
                        image = limage.resize((30,22), Image.ANTIALIAS)
                        limage2=ImageTk.PhotoImage(image)
                        Button69.config(image=limage)
                        limage.image()

But it flags up this error:

Traceback (most recent call last):
  File "C:\Users\josho\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:\Users\josho\Documents\A Dream.py", line 30, in shadoe
    Button69.config(image=limage)
  File "C:\Users\josho\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1646, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Users\josho\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1636, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "<PIL.PngImagePlugin.PngImageFile image mode=RGB size=1152x648 at 0x264638D5970>" doesn't exist

help! pls im really desperate!

1 Answers1

0
    def rescale_images(directory, size):
       for img in os.listdir(directory): 
           im = Image.open(directory+img)
           im_resized = im.resize(size, Image.ANTIALIAS)
           im_resized.save(directory+img)
rescale_images(directory_to_extract_to+"/",(256,256))
#here (256,256) is the image size
  • 1
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – blazej Jul 16 '21 at 16:01