o
    ¼>hT
  ã                   @   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	   úx/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/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    