【问题标题】:Get list of result files converted via Wand获取通过 Wand 转换的结果文件列表
【发布时间】:2013-06-26 07:29:21
【问题描述】:

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

如何获取使用 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 库本身有一种更惯用的方式。

【问题讨论】:

    标签: python imagemagick magickwand wand


    【解决方案1】:

    您可以使用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']
    

    【讨论】:

      猜你喜欢
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多