Decoding base64 from POST to use in PIL

前端 未结 4 1715
感动是毒
感动是毒 2020-12-08 04:43

I\'m making a simple API in Flask that accepts an image encoded in base64, then decodes it for further processing using Pillow.

I\'ve looked at some examples (1, 2,

4条回答
  •  攒了一身酷
    2020-12-08 04:47

    I'm using the ways mentioned above. But I'm getting this error at Image.open: cannot identify image file <_io.BytesIO object at 0x11c267590>.

    This is my code:

    image_data = re.sub('^data:image/.+;base64,', '', testBase64)
    data = Image.open(io.BytesIO(base64.b64decode(image_data)))
    

    Any ideas/ suggestions?

提交回复
热议问题