Hi, I would like some help to read files with wand in python. When I tried to open some files on wand the code gives me the following error:
raise e
wand.exceptions.CorruptImageError: unable to read image data `C:/Users/DSM/AppData/Local/Temp/magick-2964IqBjfCX3xNAi1' @ error/pnm.c/ReadPNMImage/1346
But I can convert the file through command lines (convert file.pdf file.jpg) using imagemagick.
My code in python:
def pdf_image(file, dir):
"""Convert pdf on image"""
name = re.sub('pdf', 'png', file.filename)
with Img(file=file, resolution=300) as img:
img.compression_quality = 99
img.save(filename=dir+'\'+name)
Is anyone have some thoughts about a solution?
Thank you in advance
wand.exceptions.CorruptImageError
-
- Posts: 1
- Joined: 2019-01-14T07:45:58-07:00
- Authentication code: 1152
-
- Posts: 1
- Joined: 2019-01-29T19:35:27-07:00
- Authentication code: 1152
Re: wand.exceptions.CorruptImageError
I am having the same issue, and converted the file successfully as well through CL (convert and pdftoppm).
error:
and my code:
Thanks in advance for any hint!
error:
Code: Select all
wand.exceptions.CorruptImageError: unable to read image data `/tmp/magick-9131_JaO29NKkm8N1' @ error/pnm.c/ReadPNMImage/1337
Code: Select all
from wand.image import Image
from wand.color import Color
def convert_pdf(filename, path, resolution=300):
all_pages = Image(filename=path+filename, resolution=resolution)
for i, page in enumerate(all_pages.sequence):
with Image(page) as img:
img.format = 'png'
img.background_color = Color('white')
img.alpha_channel = 'remove'
image_filename = '{}.png'.format(i)
img.save(filename=path+image_filename)