î
æ^Q\²  ã               @   sb   d  d l  m Z d  d l  m Z d  d l m Z d d „  Z d d „  Z Gd d	 „  d	 e ƒ Z d
 S)é    )Úabsolute_import)Údivision)ÚBytesIOc             C   si   | | } } |  r6 | |  k r6 |  } | | | } n  | r_ | | k r_ | } | | | } n  | | 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
    © )ZbwZbhÚwÚhZ	new_widthZ
new_heightr   r   úK/var/www/dbchiro/venv/lib/python3.4/site-packages/openpyxl/drawing/image.pyÚbounding_box   s    r	   c             C   s‚   y9 y d d  l  } Wn" t k
 r7 d d l m  } Yn XWn t k
 rY t d ƒ ‚ Yn Xt |  | j  ƒ s~ | j |  ƒ }  n  |  S)Nr   )ÚImagez+You must install PIL to fetch image objects)r
   ÚImportErrorZPILÚ
isinstanceÚopen)ÚimgZPILImager   r   r   Ú_import_image   s    r   c               @   sR   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   sm   | |  _  t | ƒ } | j d |  _ | j d |  _ y | j j ƒ  |  _ Wn t k
 rh d |  _ Yn Xd  S)Nr   r   Úpng)Úrefr   ÚsizeÚwidthÚheightÚformatÚlowerÚAttributeError)Úselfr   Úimager   r   r   Ú__init__.   s    	zImage.__init__c             C   s~   t  |  j ƒ } d } |  j d k rL | j rL | j j d ƒ | j } qL n  | st t ƒ  } | j | d |  j ƒn  | j ƒ  S)zN
        Open image and write it to a buffer when saving the workbook
        NÚgifÚjpegr   r   r   )r   r   zpng)r   r   r   ÚfpÚseekr   ÚsaveÚread)r   r   r   r   r   r   Ú_data<   s    		zImage._datac             C   s   |  j  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
   