【发布时间】:2020-10-11 14:23:53
【问题描述】:
我正在使用 jquery-cropper.js 在前端裁剪图像,然后将值传递给 Django 表单,如下所示。
def save(self):
photo = super(MyModelForm, self).save()
x = self.cleaned_data.get('x')
y = self.cleaned_data.get('y')
w = self.cleaned_data.get('width')
h = self.cleaned_data.get('height')
image = Image.open(photo.profile_pic)
cropped_image = image.crop((int(x), int(y), int(w+x), int(h+y)))
cropped_image.save(photo.profile_pic.path)
#resized_image = cropped_image.resize((min(new_width, new_height), min(new_width, new_height)), Image.LANCZOS)
#resized_image.save(photo.profile_pic.path)
return photo
目前的问题是图像在前端被裁剪得很好,但在后端却没有。我在裁剪的图片中得到黑色区域。我想要我在前端看到的精确图像。前后端坐标一致。
【问题讨论】:
标签: python-3.x django python-imaging-library