【发布时间】:2016-05-11 00:02:19
【问题描述】:
我想在 django 中为图像放置“向左旋转”和“向右旋转”按钮。 这似乎很容易,但我已经浪费了一些时间,尝试了一些在 stackoverflow 上找到的解决方案,但还没有结果。
我的模型有一个 FileField:
class MyModel(models.Model):
...
file = models.FileField('file', upload_to=path_and_rename, null=True)
...
我正在尝试这样的事情:
def rotateLeft(request,id):
myModel = myModel.objects.get(pk=id)
photo_new = StringIO.StringIO(myModel.file.read())
image = Image.open(photo_new)
image = image.rotate(-90)
image_file = StringIO.StringIO()
image.save(image_file, 'JPEG')
f = open(myModel.file.path, 'wb')
f.write(##what should be here? Can i write the file content this way?##)
f.close()
return render(request, '...',{...})
显然,它不起作用。我认为这很简单,但我还不太了解 PIL 和 django 文件系统,我是 django 的新手。
对不起,我的英语不好。感谢您的帮助。
【问题讨论】:
标签: python django python-imaging-library