
    gT
                     B    d Z ddlZddlZddlmZ  G d de      ZddZy)zO
Utility functions for handling images.

Requires Pillow as you might imagine.
    N)Filec                   6    e Zd ZdZed        Zed        Zd Zy)	ImageFilez
    A mixin for use alongside django.core.files.base.File, which provides
    additional features for dealing with images.
    c                 (    | j                         d   S )Nr   _get_image_dimensionsselfs    p/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/core/files/images.pywidthzImageFile.width       ))+A..    c                 (    | j                         d   S )N   r   r	   s    r   heightzImageFile.height   r   r   c                     t        | d      s.| j                  }| j                          t        | |      | _        | j                  S )N_dimensions_cache)close)hasattrclosedopenget_image_dimensionsr   )r
   r   s     r   r   zImageFile._get_image_dimensions   s:    t01KKEIIK%9$e%LD"%%%r   N)__name__
__module____qualname____doc__propertyr   r   r    r   r   r   r      s4    
 / / / /&r   r   c                    ddl m} |j                         }t        | d      r$| }|j	                         }|j                  d       n	 t        | d      }d}	 d}	 |j                  |      }|sn^	 |j                  |       |j                   r:|j                   j"                  |r|j%                          S |j                         S |d
z  }r	 |r|j%                          y|j                         y# t        $ r Y yw xY w# t        j                  $ r*}|j                  d   j                  d      rn Y d	}~d	}~wt        j                  $ r Y t        $ r Y w xY w# |r|j%                          w |j                         w xY 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   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es	            r   r   r   #   sh    1 A|V$99;		!	 d+D #  
99Z(Dt" wwww|| JJLIIh !OJ1 2 JJLIIhM  	 	  ::  66!9''
3  <<     JJLIIhsf   C2 E /D  !E E 2	C>=C>E D94E 9EE EE EE &F)F)r   r-   r)   django.core.filesr   r   r   r   r   r   <module>r:      s&      "& &,6 r   