î
ªÍ X|	  ã               @   sW   d  Z  d d l Z d d l Z d d l m Z Gd d „  d e ƒ Z d d d „ Z d S)	zO
Utility functions for handling images.

Requires Pillow as you might imagine.
é    N)ÚFilec               @   sR   e  Z d  Z d Z d d „  Z e e ƒ Z d d „  Z e e ƒ Z d d „  Z	 d S)	Ú	ImageFilez€
    A mixin for use alongside django.core.files.base.File, which provides
    additional features for dealing with images.
    c             C   s   |  j  ƒ  d S)Nr   )Ú_get_image_dimensions)Úself© r   úF/home/ubuntu/projects/ifolica/build/django/django/core/files/images.pyÚ
_get_width   s    zImageFile._get_widthc             C   s   |  j  ƒ  d S)Né   )r   )r   r   r   r   Ú_get_height   s    zImageFile._get_heightc             C   sA   t  |  d ƒ s: |  j } |  j ƒ  t |  d | ƒ|  _ n  |  j S)NÚ_dimensions_cacheÚclose)ÚhasattrÚclosedÚopenÚget_image_dimensionsr   )r   r   r   r   r   r      s
    	
zImageFile._get_image_dimensionsN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚpropertyÚwidthr
   Úheightr   r   r   r   r   r      s   r   Fc       	      C   sA  d d l  m } | j ƒ  } t |  d ƒ rM |  } | j ƒ  } | j d ƒ n t |  d ƒ } d } z· d } x¦ | j | ƒ } | s‡ Pn  y | j | ƒ WnX t	 j
 k
 rÞ } z! | j d j d ƒ rÉ n ‚  WYd d } ~ Xn t j
 k
 rò Yn X| j r| j j S| d	 9} qn Wd
 SWd | r/| j ƒ  n | j | ƒ Xd S)z¯
    Returns the (width, height) of an image, given an open file or a path.  Set
    'close' to True to close the file at the end if it is initially in an open
    state.
    r   )r   ÚreadÚrbTi   zError -5Né   )NN)ZPILr   ÚParserr   ÚtellÚseekr   r   ÚfeedÚzlibÚerrorÚargsÚ
startswithÚstructÚimageÚsizer   )	Zfile_or_pathr   ZPillowImageFileÚpÚfileZfile_posÚ
chunk_sizeÚdataÚer   r   r   r   !   s:    	
r   )r   r#   r   Zdjango.core.filesr   r   r   r   r   r   r   Ú<module>   s
   