o
    �?ƒZ²  ã                   @   sH   d dl mZ d dl mZ d dlmZ dd„ Zdd„ ZG dd	„ d	eƒZd
S )é    )Úabsolute_import)Údivision)ÚBytesIOc                 C   sJ   ||}}| r|| kr| }|||  }|r!||kr!|}|||  }||fS )z»
    Returns a tuple (new_width, new_height) which has the property
    that it fits within box_width and box_height and has (close to)
    the same aspect ratio as the original size
    © )ÚbwÚbhÚwÚhÚ	new_widthÚ
new_heightr   r   úH/var/www/html/env/lib/python3.10/site-packages/openpyxl/drawing/image.pyÚbounding_box   s   
r   c                 C   sb   zzdd l }W n ty   ddlm } Y nw W n ty#   tdƒ‚w t| |j ƒs/| | ¡} | S )Nr   )ÚImagez+You must install PIL to fetch image objects)r   ÚImportErrorÚPILÚ
isinstanceÚopen)ÚimgÚPILImager   r   r   Ú_import_image   s   ÿ€ÿ
r   c                   @   s8   e Zd ZdZdZdZdZdd„ Zdd„ Ze	d	d
„ ƒZ
dS )r   zImage in a spreadsheeté   z/xl/media/image{0}.{1}ÚA1c                 C   sT   || _ t|ƒ}|jd | _|jd | _z	|j ¡ | _W d S  ty)   d| _Y d S w )Nr   r   Úpng)Úrefr   ÚsizeÚwidthÚheightÚformatÚlowerÚAttributeError)Úselfr   Úimager   r   r   Ú__init__.   s   ÿzImage.__init__c                 C   sR   t | jƒ}d}| jdv r|jr|j d¡ |j}|s%tƒ }|j|| jd� | ¡ S )zN
        Open image and write it to a buffer when saving the workbook
        N)ÚgifÚjpegr   r   )r   )r   r   r   ÚfpÚseekr   ÚsaveÚread)r    r   r%   r   r   r   Ú_data<   s   

zImage._datac                 C   s   | j  | j| j¡S )N)Ú_pathr   Ú_id)r    r   r   r   ÚpathN   s   z
Image.pathN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   r*   Úanchorr"   r)   Úpropertyr,   r   r   r   r   r   '   s    r   N)	Ú
__future__r   r   Úior   r   r   Úobjectr   r   r   r   r   Ú<module>   s    