
    -Ph
                     `    d dl mZ d dlZddlmZmZ 	 d dlmZ dZn# e	$ r dZY nw xY wddZ
dS )    )BytesION   )Writer
from_array)ImageTFpil   pngc                    |dk     s|dk    rt          d          d}| j        dk    rd}nO| j        dk    r| j        d         dk    rd	}n0| j        dk    r| j        d         d
k    rd}d}nt          d          |dk    rt          rdnd}|dk    r|dk    rt          d          |dk    r| j        }| j        }|dk    r,|                     |d         |d         |d         z  f          } t          |d         |d         |dk    ||          }t          | |          }	d}
t                      5 }|                    ||	j	                   |
t          j        |                                                              d          z   }ddd           n# 1 swxY w Y   nt          st          d          t          j        |           }|dk    s|dk    rd}
d}nd}
d}t                      5 }|                    |||           |
t          j        |                                                              d          z   }ddd           n# 1 swxY w Y   |S )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   RGBr	   RGBATzInvalid image shapeautor   pypngr
   z6jpg 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                 X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/_plotly_utils/data_utils.pyimage_array_to_data_urir6      s     Q+//EFFFE
x1}}	Q39R=A--	Q39R=A--.///&'4%%W
e||5((QRRR'xY199++r!ubebem455CqE2a5TQYu+
 
 
 St,,,)YY 	Y&GGFGL)))"V%5foo6G6G%H%H%O%OPW%X%XXM	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y  	:   /#&&%<<3&==.FCC-FCYY 	Y&LLKLHHH"V%5foo6G6G%H%H%O%OPW%X%XXM	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y s&   2AFFF/AIII)r   r	   r
   )ior   r$   r
   r   r   PILr   r    r(   r6        r5   <module>r;      s           # # # # # # # #LL   LLL> > > > > >s    ''