简体   繁体   English

将 JPG 转换为 PNG

[英]Convert JPG to PNG

I have used the below code to我已经使用下面的代码

在此处输入图片说明 convert JPG into PNG file:将 JPG 转换为 PNG 文件:

But when i am running this code from the command line terminal using: python a.py "C:\\Users\\nishant.gupta2\\PycharmProjects\\jpgtopngconverter\\photo" new但是当我使用以下命令从命令行终端运行此代码时:python a.py "C:\\Users\\nishant.gupta2\\PycharmProjects\\jpgtopngconverter\\photo" new

The system is giving me the error:系统给了我错误:

 PermissionError: [Errno 13] Permission denied: 'C:\\Users\\nishant.gupta2\\PycharmProjects\\jpgtopngconverter\\photo'

My code is below:我的代码如下:

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')

It looks like this has to do with file permissions rather than your code.看起来这与文件权限有关,而不是与您的代码有关。 Your code is running under a separate user than the image folder you are specifying, depending on admin status you may get permission issues.您的代码在与您指定的图像文件夹不同的用户下运行,根据管理员状态,您可能会遇到权限问题。

You are trying to open a folder here :您正在尝试在此处打开文件夹:

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

rather then image.而不是图像。 You should specify the path of image.您应该指定图像的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM