Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Replace the use of deprecated / optional attributes
* Use getattr for is_animated attribute per the pillow doc

* Use getattr for the n_frames attribute as well
  • Loading branch information
pushfoo committed Sep 29, 2024
commit a73bafd3869c9ae8ac3dbb3ffc7ca71a27553677
10 changes: 8 additions & 2 deletions arcade/sprite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ def load_animated_gif(resource_name) -> TextureAnimationSprite:

file_name = resolve(resource_name)
image_object = PIL.Image.open(file_name)
if not image_object.is_animated:

# Pillow doc recommends testing for the is_animated attribute as of 10.0.0
# https://pillow.readthedocs.io/en/stable/deprecations.html#categories
if (
not getattr(image_object, "is_animated", False)
or not (n_frames := getattr(image_object, "n_frames", 0))
):
raise TypeError(f"The file {resource_name} is not an animated gif.")

sprite = TextureAnimationSprite()
keyframes = []
for frame in range(image_object.n_frames):
for frame in range(n_frames):
image_object.seek(frame)
frame_duration = image_object.info["duration"]
image = image_object.convert("RGBA")
Expand Down
9 changes: 5 additions & 4 deletions arcade/texture_atlas/atlas_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from weakref import WeakSet, WeakValueDictionary, finalize

import PIL.Image
from PIL.Image import Resampling
from PIL import Image, ImageDraw
from pyglet.image.atlas import (
Allocator,
Expand Down Expand Up @@ -504,10 +505,10 @@ def write_image(self, image: PIL.Image.Image, x: int, y: int) -> None:

# Resize the strips to the border size if larger than 1
if self._border > 1:
strip_top = strip_top.resize((image.width, self._border), Image.NEAREST)
strip_bottom = strip_bottom.resize((image.width, self._border), Image.NEAREST)
strip_left = strip_left.resize((self._border, image.height), Image.NEAREST)
strip_right = strip_right.resize((self._border, image.height), Image.NEAREST)
strip_top = strip_top.resize((image.width, self._border), Resampling.NEAREST)
strip_bottom = strip_bottom.resize((image.width, self._border), Resampling.NEAREST)
strip_left = strip_left.resize((self._border, image.height), Resampling.NEAREST)
strip_right = strip_right.resize((self._border, image.height), Resampling.NEAREST)

tmp.paste(strip_top, (self._border, 0))
tmp.paste(strip_bottom, (self._border, tmp.height - self._border))
Expand Down