Search code examples
pythontype-conversionpython-imaging-librarywand

How to convert wand.image.Image to PIL.Image?


I spent whole day on this problem and did not see answer in stack overflow!

I tried this but did not work:

    >> pil_image = Image.frombytes('RGBA', wand_image.size, wand_image.make_blob(format='png'), 'raw')

    ValueError: not enough image data

I appreciate every solution.


Solution

  • This worked for me:

    img_buffer = numpy.asarray(bytearray(wand_img.make_blob(format='png')), dtype='uint8')
    bytesio = io.BytesIO(img_buffer)
    pil_img = PIL.Image.open(bytesio)