Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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 图像大小调整功能未运行_Python_Python Imaging Library - Fatal编程技术网

Python 图像大小调整功能未运行

Python 图像大小调整功能未运行,python,python-imaging-library,Python,Python Imaging Library,我有一个python方法,可以调整图像的大小 def Reformat_Image(ImageFilePath,fileName,image): print("inside Reformat_Image") image_size = image.size width = image_size[0] print height = image_size[1] if(width != height): bigside = width if

我有一个python方法,可以调整图像的大小

def Reformat_Image(ImageFilePath,fileName,image):
    print("inside Reformat_Image")
    image_size = image.size
    width = image_size[0]
    print
    height = image_size[1]
    if(width != height):
        bigside = width if width > height else height
        background = Image.new('RGBA', (bigside, bigside), (255, 255, 255, 255))
        offset = (int(round(((bigside - width) / 2), 0)), int(round(((bigside - height) / 2),0)))
        background.paste(image, offset)
        background.save(fileName+"Resized.jpg")
        print("Image has been resized")
当我打电话使用它的时候

cwd = os.getcwd()
        print("Resizing picture")
        Reformat_Image(ImageFilePath =image_path,fileName=fileName,image=image)
Reformat_Image()
方法的内部永远不会运行。我能够在运行代码之前成功地打开图像几行,因此我认为我的文件名/位置应该可以正常工作

命令提示符输出:

> Resizing picture
预期产出:

> Resizing picture
> inside Reformat_Image

你是如何运行你的代码的看起来应该有一些错误消息。请回答您的问题,并提供和完成(以及发生的任何错误)。我建议您使用opencv库调整图像大小,并在OpenCV2上使用代码(cv2.resize),这允许我为其添加背景吗?这是用来调整图片大小以将内容发布到Instagram上的,它必须在一定的纵横比范围内,我不想为了实现这一点而切断图片,我正在使用命令提示符运行它。当我运行它时,我不会得到任何输出,这很奇怪,因为我的代码不想调用helper方法。当我运行代码自行调整大小时,它可以工作,但当我将其放入自己的方法中时,它不会跳转到方法的内部。没有输出说明发生这种情况时发生了什么。请尝试在不指定参数名称的情况下调用它,即:
重新格式化图像(图像路径、文件名、图像)
如何运行代码?-看起来应该有一些错误消息。请回答您的问题,并提供和完成(以及发生的任何错误)。我建议您使用opencv库调整图像大小,并在OpenCV2上使用代码(cv2.resize),这允许我为其添加背景吗?这是用来调整图片大小以将内容发布到Instagram上的,它必须在一定的纵横比范围内,我不想为了实现这一点而切断图片,我正在使用命令提示符运行它。当我运行它时,我不会得到任何输出,这很奇怪,因为我的代码不想调用helper方法。当我运行代码自行调整大小时,它可以工作,但当我将其放入自己的方法中时,它不会跳转到方法的内部。没有输出说明发生这种情况时发生了什么。请尝试在不指定参数名称的情况下调用它,即:
重新格式化图像(图像路径、文件名、图像)