使用python分割多页tiff [英] Split multi-page tiff with python

查看:111
本文介绍了使用python分割多页tiff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用python拆分多页TIFF的最佳方法是什么? PIL似乎不支持多页图像,而且我还没有找到libtiff for python的确切端口. PyLibTiff是要走的路吗?有人可以提供一个简单的示例来说明我如何解析TIFF中的多个页面吗?

What's the best way to split a multi-page TIFF with python? PIL doesn't seem to have support for multi-page images, and I haven't found an exact port for libtiff for python. Would PyLibTiff be the way to go? Can somebody provide a simple example of how I could parse multiple pages within a TIFF?

推荐答案

我确实使用ImageMagick作为外部程序将多页传真转换为可见的PNG:

I do use ImageMagick as external program to convert multi-page fax into viewable PNGs:

/usr/bin/convert /var/voip/fax/out/2012/04/fax_out_L1_17.tiff[0] -scale 50x100% -depth 16 /tmp/fax_images/fax_out_L1_17-0-m.png

是否将首页转换为PNG

does convert first page to PNG

aaa.tiff [1]将是第二页,依此类推.

aaa.tiff[1] would be second page, and so on.

或提取所有图像,请执行以下操作:

Or to extract all images, do:

convert -verbose fax_in_L1-1333564876.469.tiff a.png
fax_in_L1-1333564876.469.tiff[0] TIFF 1728x1078 1728x1078+0+0 1-bit Bilevel DirectClass 109KiB 0.030u 0:00.030
fax_in_L1-1333564876.469.tiff[1] TIFF 1728x1078 1728x1078+0+0 1-bit Bilevel DirectClass 109KiB 0.020u 0:00.010
fax_in_L1-1333564876.469.tiff[2] TIFF 1728x1078 1728x1078+0+0 1-bit Bilevel DirectClass 109KiB 0.020u 0:00.010
fax_in_L1-1333564876.469.tiff=>a-0.png[0] TIFF 1728x1078 1728x1078+0+0 1-bit Bilevel DirectClass 12KiB 0.030u 0:00.019
fax_in_L1-1333564876.469.tiff=>a-1.png[1] TIFF 1728x1078 1728x1078+0+0 1-bit Bilevel DirectClass 8KiB 0.040u 0:00.039
fax_in_L1-1333564876.469.tiff=>a-2.png[2] TIFF 1728x1078 1728x1078+0+0 1-bit Bilevel DirectClass 32KiB 0.070u 0:00.070

因此,要将一个多页TIFF拆分为多页TIFF,您必须执行:

So, to just split one multi-page TIFF into many-page TIFF you would have to execute:

convert in-12345.tiff /tmp/out-12345.tiff

,然后使用临时文件:/tmp/out-12345-*.tiff

and then work with temporary files: /tmp/out-12345-*.tiff

但是ImageMagick可以进行很多处理,因此您可能可以通过一个命令实现所需的结果.

However ImageMagick can do a lot of processing, so you can probably achieve your desired result in one command.

这篇关于使用python分割多页tiff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆