o
    <gT
                     @   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      |   d S )Nr   _get_image_dimensionsself r	   K/var/www/html/venv/lib/python3.10/site-packages/django/core/files/images.pywidth      zImageFile.widthc                 C   r   )N   r   r   r	   r	   r
   height   r   zImageFile.heightc                 C   s,   t | ds| 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   sN  ddl m} | }t| dr| }| }|d nzt| d}W n
 ty,   Y dS w d}zjd}	 ||}|s;nOz|	| W n. t
jy_ } z|jd d	rTn W Y d
}~nd
}~w tjyh   Y n	 typ   Y nw |jr|jjW |r|  S || S |d9 }q3W |r|  dS || dS |r|  w || w )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rb)NNTi   r   zError -5N   )PILr   Parserr   tellseekr   OSErrorr   feedzliberrorargs
startswithstructRuntimeErrorimagesizer   )	file_or_pathr   PillowImageFilepfilefile_pos
chunk_sizedataer	   r	   r
   r   #   sZ   



r   )F)r   r'   r#   django.core.filesr   r   r   r	   r	   r	   r
   <module>   s    