Loading Base64 String into Python Image Library

后端 未结 4 1597
旧时难觅i
旧时难觅i 2020-12-08 23:26

I\'m sending images as base64 string through ajax to django. In my django view I need to resize the image and save it in the file system.

Here is a base64 string(si

4条回答
  •  爱一瞬间的悲伤
    2020-12-08 23:59

    SOLUTION:

    Saving the opened PIL image to a file-like object solves the issue.

    pic = cStringIO.StringIO()
    image_string = cStringIO.StringIO(base64.b64decode(request.POST['file']))
    image = Image.open(image_string)
    image.save(pic, image.format, quality = 100)
    pic.seek(0)
    return HttpResponse(pic, content_type='image/jpeg')
    

提交回复
热议问题