Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close unused images #33

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions easy_pil/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -227,6 +238,8 @@ def paste(
blank.paste(image, position)
self.image = PilImage.alpha_composite(self.image, blank)

blank.close()

return self

def text(
Expand Down
1 change: 1 addition & 0 deletions easy_pil/gif_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down