如何将wand.image.Image转换成PIL.Image?
How to convert wand.image.Image to PIL.Image?
我在这个问题上花了一整天,但在堆栈溢出中没有看到答案!
我试过了但没有成功:
>> pil_image = Image.frombytes('RGBA', wand_image.size, wand_image.make_blob(format='png'), 'raw')
ValueError: not enough image data
我感谢每一个解决方案。
这对我有用:
img_buffer = numpy.asarray(bytearray(wand_img.make_blob(format='png')), dtype='uint8')
bytesio = io.BytesIO(img_buffer)
pil_img = PIL.Image.open(bytesio)
这里不涉及numpy:
pil_image = PIL.Image.open(io.BytesIO(wand_image.make_blob("png"))
一种方法是通过 numpy - 意思是将 PIL 图像导出到 numpy 数组,然后用 wand 读取它
from wand.image import Image
from IPython.display import display
with Image.from_array(np.array(img)) as ximg:
display(ximg)
或反过来
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))
我在这个问题上花了一整天,但在堆栈溢出中没有看到答案!
我试过了但没有成功:
>> pil_image = Image.frombytes('RGBA', wand_image.size, wand_image.make_blob(format='png'), 'raw')
ValueError: not enough image data
我感谢每一个解决方案。
这对我有用:
img_buffer = numpy.asarray(bytearray(wand_img.make_blob(format='png')), dtype='uint8')
bytesio = io.BytesIO(img_buffer)
pil_img = PIL.Image.open(bytesio)
这里不涉及numpy:
pil_image = PIL.Image.open(io.BytesIO(wand_image.make_blob("png"))
一种方法是通过 numpy - 意思是将 PIL 图像导出到 numpy 数组,然后用 wand 读取它
from wand.image import Image
from IPython.display import display
with Image.from_array(np.array(img)) as ximg:
display(ximg)
或反过来
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))