如何将 wand.image.Image 转换为 PIL.Image?

MGH*_*MGH 4 python type-conversion python-imaging-library wand

我在这个问题上花了一整天,但在堆栈溢出中没有看到答案!

我试过这个,但没有用:

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

    ValueError: not enough image data
Run Code Online (Sandbox Code Playgroud)

我很欣赏每一个解决方案。

MGH*_*MGH 5

这对我有用:

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


小智 5

这不涉及 numpy:

pil_image = PIL.Image.open(io.BytesIO(wand_image.make_blob("png"))
Run Code Online (Sandbox Code Playgroud)