小编Aku*_*una的帖子

为什么在使用 PIL 时出现“无法保存模式 RGBA”错误?

我正在尝试将图像转换为 PDF。我有这个代码:

def convertToPDF(folder, PDFname, deleteLast=False):
    '''
    converts all images in a folder to a PDF. 
    '''
    imageList = []
    for filename in glob.glob(folder + f'/*'):
        image=Image.open(filename)
        image.convert('RGB') # convert to RGB
        imageList.append(image)

    imageList[0].save(f'./' + PDFname + '.pdf',save_all=True, append_images=imageList[1:]) # take the first image and add everything else
Run Code Online (Sandbox Code Playgroud)

有时我会收到此错误:

 File "c:\Users\felix\OneDrive\Desktop\Programmieren\TelegrammBotProjekt\manganeloAPI.py", line 195, in convertToPDF
   imageList[0].save(f'./' + PDFname + '.pdf',save_all=True, append_images=imageList[1:]) # take the first image and add everything else
 File "C:\Users\felix\Anaconda3\lib\site-packages\PIL\Image.py", line 2151, in save
   save_handler(self, fp, filename)
 File …
Run Code Online (Sandbox Code Playgroud)

python python-imaging-library

8
推荐指数
1
解决办法
7663
查看次数

标签 统计

python ×1

python-imaging-library ×1