@@ -170,20 +170,22 @@ def correct_image_orientation(image_path):
170
170
:return: PIL.Image.Image: The image with corrected orientation.
171
171
"""
172
172
with Image .open (image_path ) as image :
173
- orientation = None
174
- try :
175
- for orientation in ExifTags .TAGS .keys ():
176
- if ExifTags .TAGS [orientation ] == 'Orientation' :
177
- break
178
- exif = dict (image .getexif ().items ())
179
- if exif .get (orientation ) == 3 :
180
- image = image .rotate (180 , expand = True )
181
- elif exif .get (orientation ) == 6 :
182
- image = image .rotate (270 , expand = True )
183
- elif exif .get (orientation ) == 8 :
184
- image = image .rotate (90 , expand = True )
185
- except (AttributeError , KeyError , IndexError ):
186
- pass
187
- return image .copy ()
173
+ image .load ()
174
+
175
+ orientation = None
176
+ try :
177
+ for orientation in ExifTags .TAGS .keys ():
178
+ if ExifTags .TAGS [orientation ] == 'Orientation' :
179
+ break
180
+ exif = dict (image .getexif ().items ())
181
+ if exif .get (orientation ) == 3 :
182
+ image = image .rotate (180 , expand = True )
183
+ elif exif .get (orientation ) == 6 :
184
+ image = image .rotate (270 , expand = True )
185
+ elif exif .get (orientation ) == 8 :
186
+ image = image .rotate (90 , expand = True )
187
+ except (AttributeError , KeyError , IndexError ):
188
+ pass
189
+ return image
188
190
189
191
0 commit comments