[英]PIL remove error "UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images"
我正在运行一个代码,该代码使用im.convert("RGB")
将图像更改为 RGB 格式。 但是,当我运行它时,它会在终端中打印UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
,虽然它不会停止程序,但很烦人并且每次都会弹出。 有什么方法可以删除它吗?
将图像转换为 RGBA
for image in os.listdir(path/to/img/dir):
im = Image.open(image)
# If is png image
if im.format is 'PNG':
# and is not RGBA
if im.mode is not 'RGBA':
im.convert("RGBA").save(f"{image}2.png")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.