o
    ^"<f	
                     @   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	   O/var/www/html/kck/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   s4  ddl m} | }t| dr| }| }|d nt| d}d}zjd}	 ||}|s.nOz|| W n. t	j
yR } z|jd drGn W Y d	}~nd	}~w tj
y[   Y n	 tyc   Y nw |jrx|jjW |rr|  S || S |d
9 }q&W |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rbTi   r   zError -5N   )NN)PILr   Parserr   tellseekr   r   feedzliberrorargs
startswithstructRuntimeErrorimagesizer   )	file_or_pathr   PillowImageFilepfilefile_pos
chunk_sizedataer	   r	   r
   r   !   sR   




r   )F)r   r&   r"   django.core.filesr   r   r   r	   r	   r	   r
   <module>   s    