14
14
from werkzeug .datastructures import FileStorage
15
15
16
16
17
+ IMAGE_EXTS = {".jpg" , ".jpeg" , ".png" }
18
+ PIL_EXTS = {"jpeg" , "png" }
19
+
20
+
17
21
def list_images (path : str ) -> List [str ]:
18
22
"""
19
23
List images in a given path
@@ -23,14 +27,12 @@ def list_images(path: str) -> List[str]:
23
27
images (list): list of exact image paths
24
28
"""
25
29
images = []
26
- image_exts = {".jpg" , ".jpeg" , ".png" }
27
- pil_exts = {"jpeg" , "png" }
28
30
for r , _ , f in os .walk (path ):
29
31
for file in f :
30
- if os .path .splitext (file )[1 ].lower () in image_exts :
32
+ if os .path .splitext (file )[1 ].lower () in IMAGE_EXTS :
31
33
exact_path = os .path .join (r , file )
32
34
with Image .open (exact_path ) as img : # lazy
33
- if img .format .lower () in pil_exts :
35
+ if img .format .lower () in PIL_EXTS :
34
36
images .append (exact_path )
35
37
return images
36
38
@@ -43,14 +45,12 @@ def yield_images(path: str) -> Generator[str, None, None]:
43
45
Yields:
44
46
image (str): image path
45
47
"""
46
- image_exts = {".jpg" , ".jpeg" , ".png" }
47
- pil_exts = {"jpeg" , "png" }
48
48
for r , _ , f in os .walk (path ):
49
49
for file in f :
50
- if os .path .splitext (file )[1 ].lower () in image_exts :
50
+ if os .path .splitext (file )[1 ].lower () in IMAGE_EXTS :
51
51
exact_path = os .path .join (r , file )
52
52
with Image .open (exact_path ) as img : # lazy
53
- if img .format .lower () in pil_exts :
53
+ if img .format .lower () in PIL_EXTS :
54
54
yield exact_path
55
55
56
56
0 commit comments