wand.exceptions.CorruptImageError

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
daniely.dsm
Posts: 1
Joined: 2019-01-14T07:45:58-07:00
Authentication code: 1152

wand.exceptions.CorruptImageError

Post 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
img.save(filename=dir+'\'+name)

Is anyone have some thoughts about a solution?

Thank you in advance
giampaolo44
Posts: 1
Joined: 2019-01-29T19:35:27-07:00
Authentication code: 1152

Re: wand.exceptions.CorruptImageError

Post by giampaolo44 »

I am having the same issue, and converted the file successfully as well through CL (convert and pdftoppm).

error:

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)
            img.save(filename=path+image_filename)
Thanks in advance for any hint!
Post Reply