
    =jK                     T    d dl mZmZ d dlmZmZmZ d dlZ ed      Zde	de	de	fdZ
y)	    )removenew_session)ImageImageFilterImageOpsNu2net_human_segimage_bytesbackground_bytesreturnc                    t        j                  t        j                  |             j	                  d      }t        j                  |      }t        |t        dddd      }|j                         d   }|j                  t        j                  d            }|j                  |       t        j                  t        j                  |            j	                  d      }t        j                  ||j                  t         j                   j"                  d	
      }t        j$                  ||      }t        j                         }|j'                  |ddd       |j)                         S )z5
    High-quality background replacement service
    RGBAT   
   )sessionalpha_matting"alpha_matting_foreground_threshold"alpha_matting_background_thresholdalpha_matting_erode_sizeg333333?)radius)      ?r   )method	centeringPNG_   )formatoptimizequality)r   openioBytesIOconvertr   exif_transposer   r   splitfilterr   GaussianBlurputalphafitsize
ResamplingLANCZOSalpha_compositesavegetvalue)r	   r
   input_image
foregroundalpha
backgroundresultoutputs           B/var/www/html/photoedit/app/modules/replaceBG/replaceBG_service.pyreplace_background_servicer6   	   s0    **RZZ45==fEK ))+6K
 +.+-!#J r"ELL11=>E
 BJJ'789AA&IJ ''	J "":z:F
 ZZ\F
KK	   ??    )rembgr   r   PILr   r   r   r    r   bytesr6    r7   r5   <module>r<      s8    % , , 	 '
(>E >U >u >r7   