3
g	
                 @   s>   d Z ddlZddlZddlmZ G dd deZd	ddZdS )
zO
Utility functions for handling images.

Requires Pillow as you might imagine.
    N)Filec               @   s0   e Zd ZdZedd Zedd 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   V/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/core/files/images.pywidth   s    zImageFile.widthc             C   s   | j  d S )N   )r   )r   r   r   r   height   s    zImageFile.heightc             C   s,   t | ds&| j}| j  t| |d| _| 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__propertyr   r
   r   r   r   r   r   r      s   r   Fc       	      C   s  ddl m} |j }t| dr6| }|j }|jd nt| d}d}zd}x|j|}|s\P y|j| W n^ t	j
k
r } z|jd jdrn W Y dd}~X n( tj
k
r   Y n tk
r   Y nX |jr|jjS |d	9 }qLW d
S | r|j  n
|j| X dS )z
    Return 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RuntimeErrorimagesizer   )	Zfile_or_pathr   ZPillowImageFilepfileZfile_pos
chunk_sizedataer   r   r   r   !   s>    



r   )F)r   r!   r   Zdjango.core.filesr   r   r   r   r   r   r   <module>   s
   