Skip to content

Commit cff2040

Browse files
committed
Performance improvement
1 parent 7781d73 commit cff2040

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

superannotate/db/projects.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,29 @@ def get_image_array_to_upload(byte_io_orig, image_quality_in_editor):
602602
Image.MAX_IMAGE_PIXELS = None
603603
im_original = Image.open(byte_io_orig)
604604
im_format = im_original.format
605-
im = ImageOps.exif_transpose(im_original)
605+
606+
# check if rotated or transposed, see ImageOps.exif_transpose
607+
exif = im_original.getexif()
608+
orientation = exif.get(0x0112)
609+
method = {
610+
2: Image.FLIP_LEFT_RIGHT,
611+
3: Image.ROTATE_180,
612+
4: Image.FLIP_TOP_BOTTOM,
613+
5: Image.TRANSPOSE,
614+
6: Image.ROTATE_270,
615+
7: Image.TRANSVERSE,
616+
8: Image.ROTATE_90,
617+
}.get(orientation)
618+
if method is not None:
619+
im = ImageOps.exif_transpose(im_original)
620+
else:
621+
im = im_original
622+
606623
width, height = im.size
607624

608625
if image_quality_in_editor == 100 and im_format in [
609626
'JPEG', 'JPG'
610-
] and im.size == im_original.size and not ImageChops.difference(im, im_original).getbbox():
627+
] and im is im_original:
611628
byte_io_lores = io.BytesIO(byte_io_orig.getbuffer())
612629
else:
613630
byte_io_lores = io.BytesIO()

superannotate/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.3.19"
1+
__version__ = "2.3.20"

0 commit comments

Comments
 (0)