@@ -81,6 +81,7 @@ def create_project(project_name, project_description, project_type):
8181 )
8282 return res
8383
84+
8485def create_project_like_project (
8586 project_name ,
8687 from_project ,
@@ -93,9 +94,12 @@ def create_project_like_project(
9394 """Deprecated. Function name changed to clone_project.
9495 """
9596 logger .warning ("Deprecated. Function name changed to clone_project." )
96- clone_project (project_name , from_project , project_description ,
97- copy_annotation_classes , copy_settings ,
98- copy_workflow , copy_project_contributors )
97+ clone_project (
98+ project_name , from_project , project_description ,
99+ copy_annotation_classes , copy_settings , copy_workflow ,
100+ copy_project_contributors
101+ )
102+
99103
100104def clone_project (
101105 project_name ,
@@ -584,25 +588,30 @@ def upload_images_from_folder_to_project(
584588 )
585589
586590
587- def get_image_array_to_upload (
588- byte_io_orig , project_type , image_quality_in_editor
589- ):
591+ def get_image_array_to_upload (byte_io_orig , image_quality_in_editor ):
590592 Image .MAX_IMAGE_PIXELS = None
591593 im = Image .open (byte_io_orig )
592594 im_format = im .format
593- im = im .convert ("RGB" )
594595 width , height = im .size
595596
596- if not image_quality_in_editor == 100 or im_format != "JPEG" :
597- byte_io_lores = io .BytesIO ()
598- im .save (
599- byte_io_lores ,
600- 'JPEG' ,
601- subsampling = 0 if image_quality_in_editor > 60 else 2 ,
602- quality = image_quality_in_editor
603- )
604- else :
597+ if image_quality_in_editor == 100 and im_format in ['JPEG' , 'JPG' ]:
605598 byte_io_lores = io .BytesIO (byte_io_orig .getbuffer ())
599+ else :
600+ byte_io_lores = io .BytesIO ()
601+ bg = Image .new ('RGBA' , im .size , (255 , 255 , 255 ))
602+ im = im .convert ("RGBA" )
603+ bg .paste (im , mask = im )
604+ bg = bg .convert ('RGB' )
605+ if image_quality_in_editor == 100 :
606+ bg .save (
607+ byte_io_lores ,
608+ 'JPEG' ,
609+ quality = image_quality_in_editor ,
610+ subsampling = 0
611+ )
612+ else :
613+ bg .save (byte_io_lores , 'JPEG' , quality = image_quality_in_editor )
614+ im = bg
606615
607616 byte_io_huge = io .BytesIO ()
608617 hsize = int (height * 600.0 / width )
@@ -611,7 +620,7 @@ def get_image_array_to_upload(
611620 byte_io_thumbs = io .BytesIO ()
612621 thumbnail_size = (128 , 96 )
613622 background = Image .new ('RGB' , thumbnail_size , "black" )
614- im .thumbnail (thumbnail_size )
623+ im .thumbnail (thumbnail_size , Image . ANTIALIAS )
615624 (w , h ) = im .size
616625 background .paste (
617626 im , ((thumbnail_size [0 ] - w ) // 2 , (thumbnail_size [1 ] - h ) // 2 )
@@ -672,7 +681,7 @@ def __upload_images_to_aws_thread(
672681 file = io .BytesIO (f .read ())
673682 try :
674683 orig_image , lores_image , huge_image , thumbnail_image = get_image_array_to_upload (
675- file , project_type , image_quality_in_editor
684+ file , image_quality_in_editor
676685 )
677686 bucket .put_object (Body = orig_image , Key = key )
678687 bucket .put_object (Body = lores_image , Key = key + '___lores.jpg' )
0 commit comments