Ë
    T]jà  ã                   óx   — d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ  G d„ d	«      Zdd
„Zdd„Zy)é    N)ÚPath)ÚFile)Úcached_property)Ú	renderSVG)ÚColor)Úsvg2rlgc                   ó|   — e Zd ZdZdd„Zed„ «       Zed„ «       Zed„ «       Z	d„ Z
d„ Zd„ Zdd
„Zd„ Zd„ Zd„ Zdd„Zy	)ÚImagez_
    Attempting to be compatible with PIL's Image, but suitable for reportlab's SVGCanvas.
    c                 ó  — t        |t        t        f«      r@t        |«      dk(  r2t        |d   t        t
        f«      rt        |d   t        t
        f«      sJ d«       ‚t        j                  |d¬«      | _        d | _	        y )Né   r   é   z4Expected `size` as tuple with two floats or integersT)ÚsizeÚuseClip)
Ú
isinstanceÚlistÚtupleÚlenÚintÚfloatr   Ú	SVGCanvasÚcanvasÚmode)Úselfr   s     úP/var/www/zogu/zoguvenv/lib/python3.12/site-packages/easy_thumbnails/VIL/Image.pyÚ__init__zImage.__init__   sp   € Ü˜$¤¤u Ô.´3°t³9À²>Ü˜4 ™7¤S¬% LÔ1´jÀÀaÁÌ3ÔPUÈ,Ô6Wð	CàBó	Cð Xô  ×)Ñ)¨t¸TÔBˆŒØˆ�	ó    c                 ó2   — | j                   | j                  fS ©N)ÚwidthÚheight©r   s    r   r   z
Image.size   s   € à�z‰z˜4Ÿ;™;Ð&Ð&r   c                 ó¤   — 	 t        | j                  j                  j                  d«      «      S # t        $ r | j                  «       d   cY S w xY w)Nr   r   ©r   r   ÚsvgÚgetAttributeÚ
ValueErrorÚgetbboxr!   s    r   r   zImage.width   sE   € ð	%Ü˜Ÿ™Ÿ™×5Ñ5°gÓ>Ó?Ð?øÜò 	%Ø—<‘<“> !Ñ$Ò$ð	%úó   ‚-0 °AÁAc                 ó¤   — 	 t        | j                  j                  j                  d«      «      S # t        $ r | j                  «       d   cY S w xY w)Nr    é   r#   r!   s    r   r    zImage.height#   sE   € ð	%Ü˜Ÿ™Ÿ™×5Ñ5°hÓ?Ó@Ð@øÜò 	%Ø—<‘<“> !Ñ$Ò$ð	%úr(   c                 óˆ   — t        d„ | j                  j                  j                  d«      j	                  «       D «       «      S )zØ
        Calculates the bounding box of the non-zero regions in the image.

        :returns: The bounding box is returned as a 4-tuple defining the
           left, upper, right, and lower pixel coordinate.
        c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr   )r   )Ú.0Úbs     r   ú	<genexpr>z Image.getbbox.<locals>.<genexpr>1   s   è ø€ ÒW !”U˜1—XÑWùs   ‚ÚviewBox)r   r   r$   r%   Úsplitr!   s    r   r'   zImage.getbbox*   s1   € ô ÑW t§{¡{§¡×'CÑ'CÀIÓ'N×'TÑ'TÓ'VÔWÓWÐWr   c                 óN  — t        «       }| j                  j                  j                  d«      |j                  _        |j                  j                  j	                  d dj
                  |Ž «       |j                  j                  j	                  d dj
                  |Ž «       |S )z­
        :param size: The requested size in pixels, as a 2-tuple: (width, height).
        :returns: The resized :py:class:`easy_thumbnails.VIL.Image.Image` object.
        Tr   ú{0}r    ú{1})r
   r   r$   Ú	cloneNodeÚsetAttributeÚformat)r   r   ÚkwargsÚcopys       r   ÚresizezImage.resize3   st   € ô
 ‹wˆØŸ+™+Ÿ/™/×3Ñ3°DÓ9ˆ�‰ŒØ�‰�‰×$Ñ$ W¨l¨e¯l©l¸DÐ.AÔBØ�‰�‰×$Ñ$ X¨|¨u¯|©|¸TÐ/BÔCØˆr   c                 ó   — | S ©z‰
        Does nothing, just for compatibility with PIL.
        :returns: An :py:class:`easy_thumbnails.VIL.Image.Image` object.
        © ©r   Úargss     r   ÚconvertzImage.convert>   ó	   € ð
 ˆr   Nc                 ó$  — t        | j                  ¬«      }| j                  j                  j	                  d«      |j                  _        |�rBt        | j                  «       «      }|d   |d   z
  |d   |d   z
  z  }|d   |d   z
  |d   |d   z
  z  }||kD  r$||d   z  }|dxx   |d   |z
  dz  z  cc<   ||d<   n#|d   |z  }|dxx   |d   |z
  dz  z  cc<   ||d<   |d   |d   z
  |d   |d   z
  f}|j                  j                  j                  d dj                  |Ž «       |j                  j                  j                  d	 d
j                  |Ž «       |j                  j                  j                  d dj                  |Ž «       |S )aD  
        Returns a rectangular region from this image. The box is a
        4-tuple defining the left, upper, right, and lower pixel
        coordinate.

        :param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
        :returns: The cropped :py:class:`easy_thumbnails.VIL.Image.Image` object.
        ©r   Tr   r   r*   r   r0   z{0} {1} {2} {3}r   r3   r    r4   )	r
   r   r   r$   r5   r   r'   r6   r7   )	r   Úboxr9   ÚbboxÚcurrent_aspect_ratioÚwanted_aspect_ratioÚ	new_widthÚ
new_heightr   s	            r   Úcropz
Image.cropE   s�  € ô ˜$Ÿ)™)Ô$ˆØŸ+™+Ÿ/™/×3Ñ3°DÓ9ˆ�‰ŒÚÜ˜Ÿ™›Ó'ˆDØ$(¨¡G¨d°1©gÑ$5¸$¸q¹'ÀDÈÁGÑ:KÑ#LÐ Ø#& q¡6¨C°©F¡?°s¸1±vÀÀAÁ±Ñ"GÐØ#Ð&9Ò9Ø/°$°q±'Ñ9�	Ø�Q“˜D ™G iÑ/°1Ñ4Ñ4“Ø#��Q’à! !™WÐ':Ñ:�
Ø�Q“˜D ™G jÑ0°AÑ5Ñ5“Ø$��Q‘Ø�q‘6˜C ™F‘? C¨¡F¨S°©V¡OÐ3ˆDØ�K‰K�O‰O×(Ñ(¨Ð4LÐ4E×4LÑ4LÈdÐ4SÔTØ�K‰K�O‰O×(Ñ(¨°,°%·,±,ÀÐ2EÔFØ�K‰K�O‰O×(Ñ(¨°<°5·<±<ÀÐ3FÔGØˆr   c                 ó   — | S r<   r=   r>   s     r   ÚfilterzImage.filterb   rA   r   c                 ó   — | S r   r=   r!   s    r   Ú	__enter__zImage.__enter__i   s   € Øˆr   c                  ó   — y r   r=   )r   ÚtypeÚvalueÚ	tracebacks       r   Ú__exit__zImage.__exit__l   s   € Ør   c                 óŒ  — d}d}t        |t        t        f«      r|}d}nt        |t        «      rt        |«      }d}t        |«      j                  j                  «       }|dk7  r|dk7  rt        d«      ‚|rt        j                  |d«      }| j                  j                  j                  |«       |r|j                  «        yy)	a}  
        Saves this image under the given filename.  If no format is
        specified, the format to use is determined from the filename
        extension, if possible.

        You can use a file object instead of a filename. In this case,
        you must always specify the format. The file object must
        implement the ``seek``, ``tell``, and ``write``
        methods, and be opened in binary mode.

        :param fp: A filename (string), pathlib.Path object or file object.
        :param format: Must be None or 'SVG'.
        :param params: Unused extra parameters.
        :returns: None
        :exception ValueError: If the output format could not be determined
           from the file name.  Use the format option to solve this.
        :exception OSError: If the file could not be written.  The file
           may have been created, and may contain partial data.
        Ú FTÚSVGz.svgzAImage format is expected to be 'SVG' and file suffix to be '.svg'ÚwN)r   ÚbytesÚstrr   ÚsuffixÚlowerr&   ÚbuiltinsÚopenr   r$   ÚwritexmlÚflush)r   Úfpr7   ÚparamsÚfilenameÚopen_fprZ   s          r   Úsavez
Image.saveo   sª   € ð* ˆØˆÜ�bœ5¤#˜,Ô'ØˆHØ‰GÜ˜œDÔ!Ü˜2“wˆHØˆGä�h“×&Ñ&×,Ñ,Ó.ˆØ�UŠ?˜v¨Ò/ÜÐ`ÓaÐaáÜ—‘˜x¨Ó-ˆBØ�‰�‰× Ñ  Ô$ÙØ�H‰H�Jð r   ))é,  re   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r    r'   r:   r@   rJ   rL   rN   rS   rd   r=   r   r   r
   r
      sq   „ ñóð ñ'ó ð'ð ñ%ó ð%ð ñ%ó ð%òXò	òóò:òòô&r   r
   c                 ób   — t        |«      }|r!|j                  j                  t        |Ž «       |S r   )r
   r   ÚsetFillColorr   )r   r   ÚcolorÚims       r   Únewro   ˜   s)   € Ü	ˆt‹€BÙØ
�	‰	×Ñœu e˜}Ô-Ø€Ir   c                 ó€  — |dk7  rt        dj                  |«      «      ‚t        | t        «      rt	        | j                  «       «      }n$t        | t        t        f«      r| }nt        d«      ‚t        |«      }|€yt        |j                  |j                  f¬«      }t        j                  ||j                  «       |S )a[  
    Opens and identifies the given SVG image file.

    :param fp: A filename (string), pathlib.Path object or a file object.
       The file object must implement :py:meth:`~file.read`,
       :py:meth:`~file.seek`, and :py:meth:`~file.tell` methods,
       and be opened in binary mode.
    :param mode: The mode.  If given, this argument must be "r".
    :returns: An :py:class:`easy_thumbnails.VIL.Image.Image` object.
    :exception FileNotFoundError: If the file cannot be found.
    :exception ValueError: If the ``mode`` is not "r", or if a ``StringIO``
       instance is used for ``fp``.
    Úrzbad mode {}zCan not open file.NrC   )r&   r7   r   r   rY   Úresolver   ÚRuntimeErrorr   r
   r   r    r   Údrawr   )r`   r   rb   Údrawingrn   s        r   Úloadrv   Ÿ   sš   € ð ˆs‚{Ü˜×-Ñ-¨dÓ3Ó4Ð4Ü�"”dÔÜ�r—z‘z“|Ó$‰Ü	�Bœœs˜Ô	$Ø‰äÐ/Ó0Ð0Ü�hÓ€GØ€Øä	�W—]‘] G§N¡NÐ3Ô	4€BÜ‡N�N�7˜BŸI™IÔ&Ø€Ir   r   )rq   )r\   Úpathlibr   Údjango.core.filesr   Údjango.utils.functionalr   Úreportlab.graphicsr   Úreportlab.lib.colorsr   Úsvglib.svglibr   r
   ro   rv   r=   r   r   ú<module>r}      s1   ðÛ Ý å "Ý 3å (Ý &å !÷Hñ HóVôr   