MT_*_*276 63 python python-imaging-library
这是一些示例代码:
import tkinter as tk
from PIL import Image, ImageTk
window = tk.Tk()
image = Image.open(r"VC.png")
image = image.resize((20, 20), Image.ANTIALIAS)
tk_image = ImageTk.PhotoImage(image)
image_label = tk.Label(window, image=tk_image)
image_label.pack()
window.mainloop()
Run Code Online (Sandbox Code Playgroud)
这是错误:
Traceback (most recent call last):
File "<module1>", line 19, in <module>
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
Run Code Online (Sandbox Code Playgroud)
slo*_*rop 118
ANTIALIAS在 Pillow 10.0.0 中被删除(在许多以前的版本中被弃用后)。现在您需要使用PIL.Image.LANCZOS或PIL.Image.Resampling.LANCZOS。
(这与所引用的算法完全相同ANTIALIAS,只是您无法再通过名称访问它ANTIALIAS。)
参考:Pillow 10.0.0 发行说明(包含已删除常量表)
简单代码示例:
import PIL
import numpy as np
# Gradient image with a sharp color boundary across the diagonal
large_arr = np.fromfunction(lambda x, y, z: (x+y)//(z+1),
(256, 256, 3)).astype(np.uint8)
large_img = PIL.Image.fromarray(large_arr)
# Resize it: PIL.Image.LANCZOS also works here
small_img = large_img.resize((128, 128), PIL.Image.Resampling.LANCZOS)
print(small_img.size)
large_img.show()
small_img.show()
Run Code Online (Sandbox Code Playgroud)
小智 12
在EasyOCR中,出现以下错误:
img = cv2.resize(img, (int(model_height*ratio), model_height), interpolation=Image.ANTIALIAS)AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
Run Code Online (Sandbox Code Playgroud)
我做了以下事情:
img = cv2.resize(img, (int(model_height*ratio), model_height), interpolation=Image.ANTIALIAS)AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
Run Code Online (Sandbox Code Playgroud)
问题一定出在 Pillow 版本 10.0 上。
| 归档时间: |
|
| 查看次数: |
102620 次 |
| 最近记录: |