Commit 83c381e 1 parent ba4d193 commit 83c381e Copy full SHA for 83c381e
File tree 2 files changed +7
-10
lines changed
2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -88,13 +88,12 @@ def load_base64(uri: str) -> np.ndarray:
88
88
encoded_data = encoded_data_parts [1 ]
89
89
decoded_bytes = base64 .b64decode (encoded_data )
90
90
91
- img = Image .open (io .BytesIO (decoded_bytes ))
92
- file_type = img .format .lower ()
93
-
94
91
# similar to find functionality, we are just considering these extensions
95
92
# content type is safer option than file extension
96
- if file_type not in ["jpeg" , "png" ]:
97
- raise ValueError (f"input image can be jpg or png, but it is { file_type } " )
93
+ with Image .open (io .BytesIO (decoded_bytes )) as img :
94
+ file_type = img .format .lower ()
95
+ if file_type not in ["jpeg" , "png" ]:
96
+ raise ValueError (f"input image can be jpg or png, but it is { file_type } " )
98
97
99
98
nparr = np .fromstring (decoded_bytes , np .uint8 )
100
99
img_bgr = cv2 .imdecode (nparr , cv2 .IMREAD_COLOR )
Original file line number Diff line number Diff line change @@ -305,11 +305,9 @@ def __list_images(path: str) -> List[str]:
305
305
if ext_lower not in {".jpg" , ".jpeg" , ".png" }:
306
306
continue
307
307
308
- img = Image .open (exact_path ) # lazy
309
-
310
- file_type = img .format .lower ()
311
- if file_type in ["jpeg" , "png" ]:
312
- images .append (exact_path )
308
+ with Image .open (exact_path ) as img : # lazy
309
+ if img .format .lower () in ["jpeg" , "png" ]:
310
+ images .append (exact_path )
313
311
return images
314
312
315
313
You can’t perform that action at this time.
0 commit comments