
    g
                     \    d dl mZ d dlZddlmZmZ 	 d dlmZ dZd	dZ
y# e	$ r dZY w xY w)
    )BytesION   )Writer
from_array)ImageTFc                 F   |dk  s|dkD  rt        d      d}| j                  dk(  rd}nU| j                  dk(  r| j                  d   dk(  rd	}n1| j                  dk(  r| j                  d   d
k(  rd}d}nt        d      |dk(  r
t        rdnd}|dk7  r|dk7  rt        d      |dk(  r| j                  }| j                  }|dk(  r| j	                  |d   |d   |d   z  f      } t        |d   |d   |dk(  ||      }t        | |      }	d}
t               5 }|j                  ||	j                         |
t        j                  |j                               j                  d      z   }ddd       |S t        st        d      t        j                   |       }|dk(  s|dk(  rd}
d}nd}
d}t               5 }|j#                  |||       |
t        j                  |j                               j                  d      z   }ddd       |S # 1 sw Y   S xY w# 1 sw Y   S xY w)a  Converts a numpy array of uint8 into a base64 png or jpg string.

    Parameters
    ----------
    img: ndarray of uint8
        array image
    backend: str
        'auto', 'pil' or 'pypng'. If 'auto', Pillow is used if installed,
        otherwise pypng.
    compression: int, between 0 and 9
        compression level to be passed to the backend
    ext: str, 'png' or 'jpg'
        compression format used to generate b64 string
    r   	   z*compression level must be between 0 and 9.F   L   RGB   RGBATzInvalid image shapeautopilpypngpngz6jpg binary strings are only available with PIL backendr   )	greyscalealphacompression)modezdata:image/png;base64,zutf-8Nzapillow needs to be installed to use `backend='pil'. Pleaseinstall pillow or use `backend='pypng'.jpgjpegzdata:image/jpeg;base64,)formatcompress_level)
ValueErrorndimshapepil_importedreshaper   r   r   writerowsbase64	b64encodegetvaluedecodeImportErrorr   	fromarraysave)imgbackendr   extr   r   r   shwimg_pngprefixstreambase64_stringpil_imgs                 U/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/_plotly_utils/data_utils.pyimage_array_to_data_urir6      s4     Q+/EFFE
xx1}	Q399R=A-	Q399R=A-.//&'%W
e|5(QRR'xxYY19++r!ubebem45CqE2a5TQYu+
 St,)Y 	Y&GGFGLL)"V%5%5foo6G%H%O%OPW%XXM	Y&  :  //#&%<3&=.FC-FCY 	Y&LLKLH"V%5%5foo6G%H%O%OPW%XXM	Y '	Y& 	Y s   AH	5A
H	HH )r   r   r   )ior   r$   r   r   r   PILr   r    r(   r6        r5   <module>r;      s6      #L
>	  Ls   ! ++