From f5705e1f0c34374a5dbbba98f741c7c529c73b5f Mon Sep 17 00:00:00 2001 From: Md Shahriyar Alam Date: Fri, 8 Dec 2023 12:08:13 +0600 Subject: [PATCH] close unused images --- easy_pil/editor.py | 13 +++++++++++++ easy_pil/gif_editor.py | 1 + 2 files changed, 14 insertions(+) diff --git a/easy_pil/editor.py b/easy_pil/editor.py index 7430d01..b82b873 100644 --- a/easy_pil/editor.py +++ b/easy_pil/editor.py @@ -54,6 +54,9 @@ def image_bytes(self) -> BytesIO: _bytes.seek(0) return _bytes + def close(self): + self.image.close() + def resize(self, size: Tuple[int, int], crop=False) -> Editor: """Resize image @@ -118,6 +121,10 @@ def rounded_corners(self, radius: int = 10, offset: int = 2) -> Editor: holder.paste(self.image, (0, 0)) self.image = PilImage.composite(holder, background, mask) + background.close() + holder.close() + mask.close() + return self def circle_image(self) -> Editor: @@ -137,6 +144,10 @@ def circle_image(self) -> Editor: holder.paste(self.image, (0, 0)) self.image = PilImage.composite(holder, background, mask) + background.close() + holder.close() + mask.close() + return self def rotate(self, deg: float = 0, expand: bool = False) -> Editor: @@ -227,6 +238,8 @@ def paste( blank.paste(image, position) self.image = PilImage.alpha_composite(self.image, blank) + blank.close() + return self def text( diff --git a/easy_pil/gif_editor.py b/easy_pil/gif_editor.py index 9b0d99b..26e38de 100644 --- a/easy_pil/gif_editor.py +++ b/easy_pil/gif_editor.py @@ -27,6 +27,7 @@ def __getattr__(self, name): def wrapper(*args, **kwargs): for frame in self.frames: getattr(frame, name)(*args, **kwargs) + getattr(frame, "close")() return wrapper