image = Image.open(io.BytesIO(data))
w, h = image.size
if w > width:
image = image.resize((width, int(1.0 * h * width / w)))
data = _PIL_to_bytes(image, format=format, quality=80)
if format is None:
After Change
if width > 0:
if actual_width > width:
new_height = int(1.0 * actual_height * width / actual_width)
image = image.resize((width, new_height))
data = _PIL_to_bytes(image, format=format, quality=90)
if format is None:
mime_type = "image/png"