File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ matplotlib
66numpy >= 1.18.5
77opencv-python-headless == 4.10.0.84
88Pillow >= 7.1.2
9- pillow-avif-plugin >= 1.5.0
109pillow-heif >= 0.18.0
1110python-dateutil
1211python-dotenv
Original file line number Diff line number Diff line change 77import yaml
88from PIL import Image
99
10+ try :
11+ import pillow_heif
12+
13+ pillow_heif .register_heif_opener (thumbnails = False ) # Register for HEIF/HEIC
14+ pillow_heif .register_avif_opener () # Register for AVIF
15+ except ImportError :
16+ pass
17+
1018
1119def check_image_path (image_path ):
1220 """
@@ -74,9 +82,18 @@ def validate_image_path(image_path):
7482def file2jpeg (image_path ):
7583 import cv2
7684
85+ # OpenCV will handle standard formats efficiently
7786 img = cv2 .imread (image_path )
78- image = cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB )
79- pilImage = Image .fromarray (image )
87+ if img is not None :
88+ # Convert BGR to RGB for PIL
89+ image = cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB )
90+ pilImage = Image .fromarray (image )
91+ else :
92+ # If OpenCV fails, the format might be HEIC/AVIF which are handled by PIL
93+ pilImage = Image .open (image_path )
94+ if pilImage .mode != "RGB" :
95+ pilImage = pilImage .convert ("RGB" )
96+
8097 buffered = io .BytesIO ()
8198 pilImage .save (buffered , quality = 100 , format = "JPEG" )
8299 return buffered .getvalue ()
You can’t perform that action at this time.
0 commit comments