我尝试使用带有魔杖作为绑定的ImageMagick将pdf转换为图像文件。我从第一步开始从pdf文件创建Image对象。
为此,
from wand.image import Image
with Image(filename="untitled.pdf[0]") as img:
# do something
我收到了这个错误
File "thumbnailer.py", line 2, in <module>
with Image(file="untitled.pdf[0]") as img:
File "C:\Python27\lib\site-packages\wand\image.py", line 2740, in __init__
self.read(file=file, resolution=resolution)
File "C:\Python27\lib\site-packages\wand\image.py", line 2805, in read
raise TypeError('file must be a readable file object'
TypeError: file must be a readable file object, but the given object does not have read() method
Exception TypeError: TypeError("object of type 'NoneType' has no len()",) in <bound method Image.__del__ of <wand.image.Image: (empty)>> ignored
当我拿出数组索引时,
from wand.image import Image
with Image(filename="untitled.pdf") as imgs:
# do something
我收到了这个错误
C:\Dev\serverless\functions-pdf-thumbnail>python thumbnailer.py
Traceback (most recent call last):
File "thumbnailer.py", line 2, in <module>
with Image(filename="untitled.pdf") as imgs:
File "C:\Python27\lib\site-packages\wand\image.py", line 2744, in __init__
self.read(filename=filename, resolution=resolution)
File "C:\Python27\lib\site-packages\wand\image.py", line 2820, in read
r = library.MagickReadImage(self.wand, filename)
WindowsError: exception: stack overflow
Exception TypeError: TypeError("object of type 'NoneType' has no len()",) in <bound method Image.__del__ of <wand.image.Image: (empty)>> ignored
我似乎无法找到任何从pdf创建Image的文档或正确示例,但是Internet上的一些示例就是这样做的。你知道出了什么问题,或者正确的做法是什么?
答案 0 :(得分:0)
您向我们显示错误的最后一个块 - 错误文本显示您仍在尝试对其执行索引
with Image(filename="untitled.pdf[0]") as img: