B
    ÔùÓ`�  ã               @   sR   d dl mZ yd dlmZ W n ek
r4   dZY nX dd„ ZG dd„ deƒZdS )	é    )ÚBytesIO)ÚImageFc             C   s&   t stdƒ‚t| t jƒs"t  | ¡} | S )Nz.You must install Pillow to fetch image objects)ÚPILImageÚImportErrorÚ
isinstancer   Úopen)Úimg© r	   ú:/tmp/pip-unpacked-wheel-zhp1095k/openpyxl/drawing/image.pyÚ_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   sb   || _ t|tƒ}t|ƒ}|j\| _| _y|j ¡ | _W n t	k
rP   d| _Y nX |r^| 
¡  d S )NÚpng)Úrefr   Ústrr   ÚsizeÚwidthÚheightÚformatÚlowerÚAttributeErrorÚclose)Úselfr   Zmark_to_closeÚimager	   r	   r
   Ú__init__   s    
zImage.__init__c             C   sN   t | jƒ}| jdkr(|j d¡ |j}ntƒ }|j|dd� | d¡ | ¡ S )zL
        Return image data, convert to supported types if necessary
        )ZgifZjpegr   r   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
   Úpath=   s    z
Image.pathN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r    Úanchorr   r   Úpropertyr"   r	   r	   r	   r
   r      s   r   N)Úior   ZPILr   r   r   r   Úobjectr	   r	   r	   r
   Ú<module>   s   

