5

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
MGH
  • 169
  • 4
  • 10

3 Answers3

5

This doesn't involve numpy:

pil_image = PIL.Image.open(io.BytesIO(wand_image.make_blob("png"))
formiga
  • 51
  • 1
  • 1
4

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)
MGH
  • 169
  • 4
  • 10
1

one way is through numpy - meaning to export PIL image into numpy array and then read it by wand

from wand.image import Image
from IPython.display import display
with Image.from_array(np.array(img)) as ximg:
    display(ximg)

or the other way around

from wand.image import Image
from matplotlib import cm

with Image(filename='rose:') as img:
    array = np.array(img)
    im = Image.fromarray(np.uint8(cm.gist_earth(array)*255))
Areza
  • 5,623
  • 7
  • 48
  • 79
  • although it requires numpy, this solution is much faster than serialising the entire image in PNG format into a temporary buffer and then parsing the PNG structure again into a third buffer. i can't believe i'm the first person to upvote this since it was posted over a year ago! – Victor Condino Dec 04 '22 at 08:50