gpt4 book ai didi

python - 获取通过 Wand 转换的结果文件列表

转载 作者:太空宇宙 更新时间:2023-11-04 06:13:29 25 4
gpt4 key购买 nike

Imagemagick是用于显示、转换和编辑光栅图像文件的开源软件套件。 Wandctypes用于 Python 的基于 ImageMagick 的绑定(bind)。

我如何获得图像文件列表,这是我使用 Wand 得到的结果?

例如,有一个 2 页的 PDF 文件 file.pdf,我将其转换为 2 个 JPEG 文件 file-0.jpgfile-1 .jpg。我如何获取列表 ['file-0.jpg', 'file-1.jpg']

目前我只是使用glob:

with Image(filename='file.pdf') as original:
with original.clone() as converted:
converted.format = 'jpeg'
converted.save(filename='file.jpg')
images = glob('*.jpg')

但也许有一种更惯用的方式通过 Wand 库本身。

最佳答案

您可以使用 Image.sequence .每个序列项都有 index .

from wand.image import Image

with Image(filename='file.pdf') as img:
img.save(filename='file.jpg')
if len(img.sequence) > 1:
images = ['file-{0.index}.jpg'.format(x) for x in img.sequence]
else:
images = ['file.jpg']

关于python - 获取通过 Wand 转换的结果文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17314044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com