def crop_image(self, data_image, ratio):
image = Image.open(data_image)
cropped_image = image.crop(ratio)
# saving image to memory
thumb_io = io.BytesIO()
cropped_image.save(
thumb_io,
data_image.content_type.split('/')[-1].upper()
)
# creating new InMemoryUploadedFile() based on the modified file
file = InMemoryUploadedFile(
thumb_io,
'photo',
data_image._get_name(),
data_image.content_type,
None, None,
)
return file
评论列表
文章目录