def save(self, *args, **kwargs):
"""overrides the save method for the model
"""
# fetches the original image from its url and loads it to memory
image_request = requests.get(self.original_image)
image_bytes = io.BytesIO(image_request.content)
image = Image.open(image_bytes)
filename = os.path.basename(self.original_image)
# call the apply_effect method on the in-memory original image
image_with_effect = apply_effects(image, self.effects)
# creat an empty in-memory bytes section to hold the edited image
edited_image = io.BytesIO()
image_with_effect.save(edited_image, format=image.format)
# initiate an upload from the in-memory edited image
edited_file = InMemoryUploadedFile(
edited_image,
None,
filename,
'image/jpeg',
edited_image.tell,
None
)
self.phedited_image.save(
filename,
edited_file,
save=False,
)
super(PheditedImage, self).save(*args, **kwargs)
评论列表
文章目录