I want to use urllib and Tkinter to resize an image. However, I do not know how to resize the image. This is not my code, but I would like to see how it would be done using this code.
from io import BytesIO
import urllib
import urllib.request
import tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
root.geometry("500x500")
url = "https://www.thoughtco.com/thmb/O8fvqeXnAtOZ_L4eQ-aCRFKou_I=/768x0/filters:no_upscale():max_bytes(150000):strip_icc()/atlantic-bottlenose-dolphin--jumping-high-during-a-dolphin-training-demonstration-154724035-59ce93949abed50011352530.jpg"
with urllib.request.urlopen(url) as u:
raw_data = u.read()
img = Image.open(BytesIO(raw_data))
iimage = ImageTk.PhotoImage(img)
label = tk.Label(image=iimage)
label.pack()
root.mainloop()
When I try to resize it:
iimage = ImageTk.PhotoImage(img.resize(50,50, Image.ANTIALIAS))
It gives me this error:
ValueError: Unknown resampling filter (50). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)
You need to pass size as a tuple
. So it would look like this:
iimage = ImageTk.PhotoImage(img.resize((50,50), Image.ANTIALIAS))