您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将通过PIL创建的图像保存到Django模型

将通过PIL创建的图像保存到Django模型

我用以下代码解决了这个问题:

       image = ContentFile(b64decode(part.get_payload()))
       im = Image.open(image)
       tempfile = im.rotate(270)
       tempfile_io =StringIO.StringIO()
       tempfile.save(tempfile_io, format='JPEG')
       image_file = InMemoryUploadedFile(tempfile_io, None, 'rotate.jpg','image/jpeg',tempfile_io.len, None)
       img = Photo(user=user)
       img.img.save('rotate.jpg', image_file)
       img.save()

在这里找到了答案。如何将PILImage转换为DjangoFile。完美无缺!

Go 2022/1/1 18:39:07 有461人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶