python - 为什么我在保存 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)
。
有人可以解释这里发生了什么吗?也许是函数中的channel
和operator
参数的结果composite_channel
?
解决方案
推荐阅读
- python - dtype 没有提供足够的数据类型精度。备择方案?
- java - 如何使用 pom.xml 将参数传递给 java 文件
- c++ - 什么是 void (*op)(T &) 和 void (*op)(T &, void *)?
- python-3.x - 如何在 Tkinter 条目小部件中获取选择的开始和结束索引?
- java - 如何使用 Java 或 Java Native Access 读取本地打开的 MS Word 文档的文本
- php - 类 stdClass 的对象无法转换为字符串 - 将 php 更新为 php 7.2 后 Joomla K2 Store 错误
- java - 从 JAVA https 客户端调用托管在 IIS Web 服务中的 https Web 服务
- ios - 在 arkit ios swift 中点击 SCNNode 上的位置
- c - 为什么 UDP 组播服务器没有响应?
- angular - Angular:FileReader - 从列表中的文件中获取名称