问题
I'd like to ask if someone has ever dealt with the same type of error with different files. My friend and I did a code to convert PDF files to JPG images, but quite often it gives an error like:
"wand.exceptions.CorruptImageError: unable to read image data C:/Users/ACERES~1/AppData/Local/Temp/magick-1364LojCg7PrnIwH1' @ error/pnm.c/ReadPNMImage/1344
Exception TypeError: TypeError("object of type 'NoneType' has no len()",) in <bound method Image.__del__ of <wand.image.Image: (empty)>> ignored"
The files we are working with are not corrupted and they do open propely. Not only that, there quite a number of PDFs that work fine and this error doesn't show up.
Any ideas on to solve that?
Thanks for any tips and effort, in advance.
We are using:
- Windows 10 64-bits
- JetBrains PyCharm Community Edition 2018.1 x64;
- ImageMagick-6.9.9-50-Q8-x64-dll (Win64 dynamic at 8 bits-per-pixel component);
- the following libraries: { from wand.image import Image from pyPdf import PdfFileReader, PdfFileWriter import io import glob import os.path };
* The error occurs here:
for page_num in xrange(reader.getNumPages()):
writer = PdfFileWriter()
writer.addPage(reader.getPage(page_num))
# outputStream = file(p, "w+")
pdf_bytes = io.BytesIO()
writer.write(pdf_bytes)
pdf_bytes.seek(0)
img = Image(file=pdf_bytes, resolution=100) **(*error in this line)**
img.convert("jpg")
img.save(filename=dayName+'/' + str(page_num) + ".jpg")
来源:https://stackoverflow.com/questions/50723020/constant-error-using-imagemagick-with-python-in-windows