Page 1 of 1


Posted: 2019-01-14T08:02:00-07:00
by daniely.dsm
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'\'+name)

Is anyone have some thoughts about a solution?

Thank you in advance

Re: wand.exceptions.CorruptImageError

Posted: 2019-01-29T19:46:40-07:00
by giampaolo44
I am having the same issue, and converted the file successfully as well through CL (convert and pdftoppm).


Code: Select all

wand.exceptions.CorruptImageError: unable to read image data `/tmp/magick-9131_JaO29NKkm8N1' @ error/pnm.c/ReadPNMImage/1337
and my code:

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)
Thanks in advance for any hint!