Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将JPG转换为PNG_Python_Python 3.x_Python Imaging Library_Sys - Fatal编程技术网

Python 将JPG转换为PNG

Python 将JPG转换为PNG,python,python-3.x,python-imaging-library,sys,Python,Python 3.x,Python Imaging Library,Sys,我已使用以下代码 将JPG转换为PNG文件: 但是当我从命令行终端使用:python a.py C:\Users\nishant.gupta2\PycharmProjects\jpgtopngconverter\photo new运行此代码时 系统给了我一个错误: PermissionError: [Errno 13] Permission denied: 'C:\\Users\\nishant.gupta2\\PycharmProjects\\jpgtopngconverter\\photo

我已使用以下代码

将JPG转换为PNG文件:

但是当我从命令行终端使用:python a.py C:\Users\nishant.gupta2\PycharmProjects\jpgtopngconverter\photo new运行此代码时

系统给了我一个错误:

 PermissionError: [Errno 13] Permission denied: 'C:\\Users\\nishant.gupta2\\PycharmProjects\\jpgtopngconverter\\photo'
我的代码如下:

import sys
import os
from PIL import Image

image_folder=sys.argv[1]

output_folder=sys.argv[2]

if not os.path.exists(output_folder):
    os.mkdir(output_folder)


for items in os.listdir(image_folder):

    im= Image.open(f'{image_folder}')
    im.save(f'{output_folder}.png','png')

看起来这与文件权限有关,而不是与代码有关。您的代码是在指定的图像文件夹之外的单独用户下运行的,根据管理员状态,您可能会遇到权限问题。

您试图在此处打开文件夹:

im= Image.open(f'{image_folder}')

而不是图像。您应该指定图像的路径

到底是什么问题?从那个错误消息中,您理解/不理解什么?