给定短小的5页PDF文件(附加在底部),以及以下要转换为多页TIFF的python代码:
from wand.image import Image
with Image(filename='5-page-pdf.pdf', resolution=200) as img:
img.type = "grayscale"
img.format = "tiff"
img.compression = "lzw"
img.save(filename="test.tiff")生成一个TIFF文件,该文件的第2-4页显示为深灰色(或透明)背景上的黑色文本。其他图像处理库无法打开或渲染该文件。
使用Wand使用的ImageMagick转换相同的PDF效果很好。
convert -density 200 5-page-pdf.pdf -type grayscale -compress lzw 5-page-pdf.tiff这会生成一个文件,该文件可以与其他图像库一起使用,并且在TIFF查看器中显示正确。
我试着移除alpha通道,我试着将背景颜色设置为‘白色’,还有一些其他的东西,但都没有用。从Wand中出来的TIFF总是乱码。如果它在ImageMagick中是可行的,那么它在魔杖中也应该是可行的,对吧?我遗漏了什么参数或设置?
发布于 2020-03-11 04:12:24
设置img.alpha_channel属性似乎没有跨页传播。
尝试此解决方法
from wand.api import library
from wand.image import Image
with Image(filename="5-page-pdf.pdf", resolution=200) as img:
img.type = 'grayscale'
img.compression = "lzw"
# Manually iterate over all page, and turn off alpha channel.
library.MagickResetIterator(img.wand)
for idx in range(library.MagickGetNumberImages(img.wand)):
library.MagickSetIteratorIndex(img.wand, idx)
img.alpha_channel = 'off'
img.save(filename="test.tiff")https://stackoverflow.com/questions/60624547
复制相似问题