【发布时间】:2021-10-03 10:23:17
【问题描述】:
我想使用 urllib 和 Tkinter 来调整图像大小。但是,我不知道如何调整图像大小。这不是我的代码,但我想看看如何使用此代码完成。
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()
当我尝试调整它的大小时:
iimage = ImageTk.PhotoImage(img.resize(50,50, Image.ANTIALIAS))
它给了我这个错误:
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)
【问题讨论】:
标签: python image tkinter resize urllib