i am trying to scramble an image using pillow, i have my code but the keep getting this Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\matthew.vandamboy\PycharmProjects\KatePixelation\venv\lib\site-packages\PIL\ImageFile.py", line 166, in load
seek = self.load_seek
AttributeError: 'JpegImageFile' object has no attribute 'load_seek'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\matthew.vandamboy\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:/Users/matthew.vandamboy/PycharmProjects/KatePixelation/imageManipulation.py", line 10, in <lambda>
self.buttonscram = tk.Button(master, text="Scramble", command= lambda : self.scrambledeggs(self.width , self.height, self.file ))
File "C:/Users/matthew.vandamboy/PycharmProjects/KatePixelation/imageManipulation.py", line 25, in scrambledeggs
setsized = self.img.resize((width , height))
File "C:\Users\matthew.vandamboy\PycharmProjects\KatePixelation\venv\lib\site-packages\PIL\Image.py", line 1876, in resize
return self.copy()
File "C:\Users\matthew.vandamboy\PycharmProjects\KatePixelation\venv\lib\site-packages\PIL\Image.py", line 1112, in copy
self.load()
File "C:\Users\matthew.vandamboy\PycharmProjects\KatePixelation\venv\lib\site-packages\PIL\ImageFile.py", line 169, in load
seek = self.fp.seek
AttributeError: 'NoneType' object has no attribute 'seek'
Here's my code; how would I stop this from happening?
from PIL import Image,ImageStat
import numpy as np
import tkinter as tk
import easygui
class gui:
def __init__(self, master):
self.master = master
self.buttonchoose = tk.Button(master, text="Choose image", command= self.fetchimage)
self.buttonscram = tk.Button(master, text="Scramble", command= lambda : self.scrambledeggs(self.width , self.height, self.file ))
self.buttonscram.pack()
self.buttonchoose.pack()
def fetchimage(self):
file = easygui.fileopenbox()
with Image.open(file) as self.img:
self.width, self.height = self.img.size
self.file = file
print(self.width , self.height)
return file
def scrambledeggs(self , width , height, file):
setsized = self.img.resize((width , height))
thechanger = np.array(setsized)
for i in range(width):
for j in range(height):
for p in range(3):
if thechanger[i][j][p] % 2 == 0:
thechanger[i][j][p] = 255
final = Image.fromarray(im, 'RGB')
final.show()