我想优化用户从管理网站上传的图片,并存储原始图片以及优化图片
def save_model(self, request, obj, form, change):
if obj.image:
filename = obj.image.name.split('.')[:-1]
obj.save()
img = Image.open(obj.image)
print "Before Size: ", img.size
w, h = img.size
size = min(800.0 / w, 800.0 / h)
w, h = int(w * size), int(h * size)
print "After Size:", w, h
img = img.resize((w, h), Image.BICUBIC)
path = obj.image.path.split('\\')[:-1]
new_path = "\\".join(path) + "\\{}.jpeg".format("".join(filename))
img.save('{}'.format(new_path))
obj.image = img
obj.save()
AttributeError: _committed
任何有用的建议都将不胜感激!