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
6
6
numpy >= 1.18.5
7
7
opencv-python-headless == 4.10.0.84
8
8
Pillow >= 7.1.2
9
- pillow-avif-plugin >= 1.5.0
10
9
pillow-heif >= 0.18.0
11
10
python-dateutil
12
11
python-dotenv
Original file line number Diff line number Diff line change 7
7
import yaml
8
8
from PIL import Image
9
9
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
+
10
18
11
19
def check_image_path (image_path ):
12
20
"""
@@ -74,9 +82,18 @@ def validate_image_path(image_path):
74
82
def file2jpeg (image_path ):
75
83
import cv2
76
84
85
+ # OpenCV will handle standard formats efficiently
77
86
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
+
80
97
buffered = io .BytesIO ()
81
98
pilImage .save (buffered , quality = 100 , format = "JPEG" )
82
99
return buffered .getvalue ()
You can’t perform that action at this time.
0 commit comments