We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
描述: 在为图片添加水印时,遇到了 ANTIALIAS 属性相关的错误。具体表现为当用户尝试使用 ANTIALIAS 来调整水印图片大小时,程序抛出以下错误:
ANTIALIAS
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
resize
Image.ANTIALIAS
水印图片应被正确缩放并添加到目标图片上,不应抛出任何错误。
在调整水印图片大小时,脚本抛出 AttributeError,提示 ANTIALIAS 属性不存在,导致水印无法正常添加。
AttributeError
经过调查,发现 ANTIALIAS 属性在最新版本的 Pillow 中已被弃用,并被 Image.Resampling.LANCZOS 取代。要解决这个问题,需要将 Image.ANTIALIAS 替换为 Image.Resampling.LANCZOS,并确保导入了合适的模块。以下是修改后的代码:
Image.Resampling.LANCZOS
from PIL import Image def add_to_pic(self, pic_path, img_pic, size, count, mode): mark_pic_path = '' if mode == 1: mark_pic_path = 'Img/SUB.png' elif mode == 2: mark_pic_path = 'Img/LEAK.png' elif mode == 3: mark_pic_path = 'Img/UNCENSORED.png' img_subt = Image.open(mark_pic_path) scroll_high = int(img_pic.height / size) scroll_wide = int(scroll_high * img_subt.width / img_subt.height) # 修改这一行 img_subt = img_subt.resize((scroll_wide, scroll_high), Image.Resampling.LANCZOS) r, g, b, a = img_subt.split() # 获取颜色通道,保持png的透明性 # 封面四个角的位置 pos = [ {'x': 0, 'y': 0}, {'x': img_pic.width - scroll_wide, 'y': 0}, {'x': img_pic.width - scroll_wide, 'y': img_pic.height - scroll_high}, {'x': 0, 'y': img_pic.height - scroll_high}, ] img_pic.paste(img_subt, (pos[count]['x'], pos[count]['y']), mask=a) img_pic.save(pic_path, quality=95)
Image
如果没有更新 Pillow,可以使用以下命令来更新:
pip install --upgrade Pillow
The text was updated successfully, but these errors were encountered:
No branches or pull requests
描述:
在为图片添加水印时,遇到了
ANTIALIAS
属性相关的错误。具体表现为当用户尝试使用ANTIALIAS
来调整水印图片大小时,程序抛出以下错误:复现步骤
resize
方法对水印图片进行缩放,并传入Image.ANTIALIAS
作为参数。预期行为
水印图片应被正确缩放并添加到目标图片上,不应抛出任何错误。
实际行为
在调整水印图片大小时,脚本抛出
AttributeError
,提示ANTIALIAS
属性不存在,导致水印无法正常添加。环境信息
建议的解决方案
经过调查,发现
ANTIALIAS
属性在最新版本的 Pillow 中已被弃用,并被Image.Resampling.LANCZOS
取代。要解决这个问题,需要将Image.ANTIALIAS
替换为Image.Resampling.LANCZOS
,并确保导入了合适的模块。以下是修改后的代码:关键修改点
Image.ANTIALIAS
替换为Image.Resampling.LANCZOS
。Image
模块,并且 Pillow 版本足够新,支持Image.Resampling.LANCZOS
。如果没有更新 Pillow,可以使用以下命令来更新:
The text was updated successfully, but these errors were encountered: