首页 > 解决方案 > 为什么我在保存 Wand Image 时会收到多个文件?

问题描述

我有以下代码:

def resizeImg(img, width, height):
    outerImg = img(width=width, height=height, background=Color("WHITE"))
    outerImg.units='pixelsperinch'
    outerImg.resolution = (300, 300)
    outerImg.format = img.format.lower()
    outerImg.composite_channel('undefined', img, 'over', int((width - img.width) / 2), int((height - img.height) / 2))
    return outerImg

for file in os.listdir(): 
    if os.path.splitext(file)[1] in ('.tif', '.jpeg', '.jpg'): 
            
        with Image() as img: 
            
            fname = ntpath.basename(file).split('.')[0] # BC154360-ANG
            img.read(filename=file)
            img.units='pixelsperinch'
            img.resolution = (300, 300) 
            img.compression_quality = 99 
            img.format = 'jpg' 
            dim = max(img.width, img.height) 
            img.resize(height=dim, width=dim) # make image square
            img.resize(height=1500, width=1500) # set image size to 1500x1500
            img.units='pixelsperinch'
            img.resolution = (72, 72)
            img.save(filename = jpg_location + fname + '.jpg') # .jpg

问题是当我运行它时我得到了多个文件,它们都略有不同。似乎每张图像都经过了不同的处理。“-0”图像似乎是正确的,我运行时的结果也是如此display(img)

运行上述代码块的结果。 第一张图是对的。

有人可以解释这里发生了什么吗?也许是函数中的channeloperator参数的结果composite_channel

标签: pythonimage-processingimagemagickwand

解决方案


推荐阅读