def convert_image(image, width, height):
"""
resize the image to the correct size needed by the template.
"""
name = image.name
pio = Image.open(image)
if width is None:
img = resizeimage.resize_height(pio, height, validate=False)
else:
img = resizeimage.resize_cover(pio, [width, height], validate=False)
new_image_io = BytesIO()
img.save(new_image_io, format=pio.format)
image.delete(save=False)
image.save(
name,
content=ContentFile(new_image_io.getvalue()),
save=False
)
评论列表
文章目录