PIL图片拒绝保存文件

时间:2018-09-04 20:40:13

标签: python-3.x pycharm python-imaging-library

我正在尝试使用Pillow的图像模块编写一个简单的脚本,以将图像从RGBA转换为RGB,这是一个非常简单的任务。但是,图像无法安全保存,这是怎么回事?

这是整个.py文件。 (.py和src_images文件夹都在同一目录中。)

from PIL import Image

image_debug = Image.open('src_images/image1.png')

image_debug = image_debug.convert('RGB')
image_debug.save = ('converted_image.png')
image_debug = Image.open('converted_image.png')

运行时,出现以下错误:

Traceback (most recent call last):
  File "/home/armin/PycharmProjects/dynamic-wal-changer/tests/DEBUG.py", line 7, in <module>
    image_debug = Image.open('converted_image.png')
  File "/home/armin/PycharmProjects/dynamic-wal-changer/venv/lib/python3.7/site-packages/PIL/Image.py", line 2580, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'converted_image.png'

Process finished with exit code 1

无论出于何种原因,它都拒绝保存图像,我们将不胜感激!

谢谢!

1 个答案:

答案 0 :(得分:0)

线

image_debug.save = ('converted_image.png')

应该是

image_debug.save('converted_image.png')
相关问题