Skip to content

Commit cd4f6dc

Browse files
authored
Add support for loading webp images (#346)
This has been supported in pygame and can now be used here, helpfully fixing the tutorial which currently instructs users to right click and "save as" a webp image. I didn't see any reference to the file type the image was loaded from for the test case, so I took the fact that instantiating the Actor didn't crash to mean the webp image loading works (since there's only a webp image with the name "alien_as_webp"). Ref #341
2 parents 9165448 + f8157e9 commit cd4f6dc

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/pgzero/loaders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __dir__(self):
172172

173173

174174
class ImageLoader(ResourceLoader):
175-
EXTNS = ['png', 'gif', 'jpg', 'jpeg', 'bmp']
175+
EXTNS = ['png', 'gif', 'jpg', 'jpeg', 'bmp', 'webp']
176176
TYPE = 'image'
177177

178178
def _load(self, path):

test/images/alien_as_webp.webp

1.59 KB
Loading

test/test_webp_loader.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import unittest
2+
3+
import pygame
4+
5+
from pgzero.actor import Actor
6+
from pgzero.loaders import set_root
7+
8+
9+
TEST_DISP_W, TEST_DISP_H = (200, 100)
10+
11+
12+
class WebpLoaderTest(unittest.TestCase):
13+
@classmethod
14+
def setUpClass(self):
15+
pygame.init()
16+
pygame.display.set_mode((TEST_DISP_W, TEST_DISP_H))
17+
set_root(__file__)
18+
19+
@classmethod
20+
def tearDownClass(self):
21+
pygame.display.quit()
22+
23+
def test_loader_finds_webp(self):
24+
actor = Actor("alien_as_webp")
25+
26+
# Just instantiating the actor shows webp image loading works
27+
assert actor

0 commit comments

Comments
 (0)