Skip to content

Commit

Permalink
Merge pull request #33 from shahriyardx/feat/gif
Browse files Browse the repository at this point in the history
close unused images
  • Loading branch information
shahriyardx authored Dec 8, 2023
2 parents ce49e38 + f5705e1 commit d0cfd56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit d0cfd56

Please sign in to comment.