image context manager

This commit is contained in:
Devaev Maxim 2020-05-29 18:53:17 +03:00
parent 3389dbe048
commit a5fcafe2a5

View File

@ -42,9 +42,9 @@ def _inner_make_text_jpeg(width: int, height: int, quality: int, text: str) -> b
image = Image.new("RGB", (width, height), color=(0, 0, 0))
draw = ImageDraw.Draw(image)
draw.multiline_text((20, 20), text, font=_get_font(), fill=(255, 255, 255))
bio = io.BytesIO()
image.save(bio, format="jpeg", quality=quality)
return bio.getvalue()
with io.BytesIO() as bio:
image.save(bio, format="jpeg", quality=quality)
return bio.getvalue()
@functools.lru_cache()